Back to problems

Generate all permutations of a list

Algorithm · Oracle · Easy

You are given a collection of distinct integers stored in an array nums. Your task is to generate every possible ordering of these elements. The result may be printed in any sequence you like. Input Format The first line contains a single integer n — the number of elements. The second line lists the n space‑separated integers that form the array nums. Output Format Print each permutation on its own line, with the numbers separated by a single space. Example 1 Explanation:…

Checking your access…