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.

Community Answers

1 answer from the community

Expert Answer

Unlock Full Access

Answer any un-answered question from our database to unlock all community answers for 30 days.

Give & Take

Practice More Questions

1 answer published. Last candidate submission on Oct 10 2026, 6:02am PDT. Interview question asked to Software Engineers interviewing at MasterClass, Nutanix, Panasonic and other companies. Original question asked: Implement the next permutation algorithm.. Question last reported by a candidate interviewing at Analog Devices for a Software Engineer interview on Sep 30 2026, 10:00pm PDT.