Approach Explanation (o゜▽゜)o☆
- I scanned from right to left to find the first element that breaks the descending order using the first while loop.
- I looked for the smallest element greater than the pivot on its right.
- I swapped the pivot and successor.
- I reversed the part of the array after the pivot to get the next lexicographical order.
- If no pivot exists, I reversed the whole array to get the lowest order.
Method Used: (/^▽^)/
- Right-to-left scan.
- Swapping.
- Reverse suffix.
- In-place rearrangement.
- extra space.
- Single pass logic.

Top comments (0)