Meta Variant for Next Permutation (LC31)
2249

Hey y’all! Here’s another solution for another frequently asked Meta question, Leetcode 31 Next Permutation and its variant.

I’ll preface this by saying this Leetcode problem is not intuitive and it’s one of those “You must’ve have solved it before”. I personally rote memorized it for my Meta interview but as always, this isn’t the most reliable way to go about it, especially because there’s a lot of specific logic in the algorithm. Not only that, but because the variant is the complete opposite, it’s even tougher to keep both problem implementations in the brain.
But yes, the variant is the reverse of the original Leetcode problem: what if you had to find the previous permutation? Or in other words, implement std::prev_permutation?

I know I say in the video it’s a 50/50 chance of being asked the OG or the variant but it definitely feels like the variant is asked more frequently. It’s arguable though.

Check it out (or not!):
Leetcode 31: Next Permutation

Reference to the OG LC problem: https://leetcode.com/problems/next-permutation/description/

Good luck on your phone screens & onsite loops.

Comments (4)