solulubeta
Sign in
Recursion & Memo / Choices and backtracking
02.06 · Problem

Permutations

Medium Loop with used[] LC 46 Pro

Return every ordering of the given distinct numbers. Any order is fine.

Examples

Example 1

Input:  nums = [1, 2, 3]
Output: [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]

Example 2

Input:  nums = [0, 1]
Output: [[0, 1], [1, 0]]
solulu Pro

Continue this problem with Pro

Inside: step-by-step hints · 8 hidden tests · reference solutions · code editor.

Lifetime ₹1,999 ₹999 · Launch offer
Mark this problem as solved when you are finished.

Item 17 of 44 · updated 2026-10-13