Permutations

Medium · Backtracking · Array · Backtracking

Problem

Given an array nums of distinct integers, return every possible ordering of them, in any order.

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]]

3! = 6 orderings.

Input: nums = [1]
Output: [[1]]

Constraints

Approaches

Related problems

Start free on Cariara · Coding problems · System design studio

Starting Python
No results yet.

          
↑↓ move ↵ open esc close

Labs

Loading labs…

Run with your own input

Starting Python

Loading Python…