26. Generate Permutations of an Array
β GFG solution to the Generate Permutations problem: find all possible permutations of array elements using backtracking and STL algorithms. π
π§© Problem Description
π Examples
Example 1
Input: arr[] = [1, 2, 3]
Output: [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
Explanation: There are 6 possible permutations (3! = 6) of the array.Example 2
Input: arr[] = [1, 3]
Output: [[1, 3], [3, 1]]
Explanation: There are 2 possible permutations (2! = 2) of the array.π Constraints
β
My Approach
STL next_permutation Approach
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
β Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated