WorkspaceProblem lab
ALGORITHM VISUALIZER

Permutations

Opening the interactive workspace…

Understanding Permutations

Return every permutation of the distinct integers in nums, in any order.

How it works

Choose each unused value, explore its completions, then undo the choice.

Track a path and which indices are used. Save a copy when the path contains every value. Try every unused index and undo it before the next branch.

Try an example

Input: nums = [1, 2, 3]

Output: [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]

Choose each unused value, explore its completions, then undo the choice.

Constraints

  • 0–5 distinct integers between -1,000,000 and 1,000,000.
  • The empty input has one permutation: [].

Use the simulator

Change the input, then choose Visualize input. Use Next and Previous to inspect each decision, or Play to advance automatically. Compare approaches and their complexity. Choose Try yourself to write JavaScript, select My code and Visualize code to inspect its execution, or Run Tests to check results.

Execution happens in your browser. Drafts are saved locally; avoid entering secrets or sensitive information.

Related concepts and complexity