Skip to content
CampusEduX

Generate All Permutations

Mediumjavapythonccppjavascript

Given an array of distinct integers, generate every ordering of its elements, in lexicographic order.

Input Format

The first line contains an integer N. The second line contains N space-separated distinct integers.

Output Format

Print N! lines, one per permutation, in lexicographic order (based on the values), space-separated.

Related Problems

  • Generate All Subsets
    Medium · java, python, c, cpp, javascript
    Solve Problem
  • Tower of Hanoi
    Medium · java, python, c, cpp, javascript
    Solve Problem
  • Rat in a Maze
    Medium · java, python, c, cpp, javascript
    Solve Problem

Input (stdin)

Output

Run your code to see output here...