Permutations Problem

Permutations Problem — ExecCode Medium DSA Practice

Solve the Permutations problem on ExecCode. Free online medium DSA practice in Backtracking. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Given an array nums of distinct integers, return all the possible permutations in any order. Build every ordering by picking one unused element at a time and backtracking once a full-length path is recorded.

Examples

Input nums = [1, 2, 3]; Output [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]. Input nums = [0, 1]; Output [[0, 1], [1, 0]]. Input nums = [1]; Output [[1]]

Constraints

1 <= nums.length <= 6 All integers in nums are unique.

Practice Permutations free on ExecCode. Browse DSA problems, topic map, and placement guides.