algorithms.tutorialhorizon.com

Lexicographically previous permutation With One swap | Algorithms

Given an array of integers (in particular order or permutation of a set of numbers), write an algorithm to find the lexicographically previous permutation of the given permutation with only one swap. This problem can also be asked as "Given a permutation of numbers you need to find the next smaller premutation OR largest permutation which is smaller than the given permutation.