Coding

Implement the next permutation algorithm.

Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such an arrangement is not possible, it must rearrange it as the lowest possible order.

Input: nums = [3,2,1]

Output: [1,2,3]

Explanation: The sequence is strictly decreasing, meaning it is the last possible permutation. It wraps around to the lowest possible order.

Was asked at

Practice this question with AI

First session is free - no credit card required.

Go Premium

More interviews, more skills, more success.

No answers yet

Be the first to share your approach to this question

Practice More Questions