logo
Problems

Previous Permutation

Problem

Given a list of integers, which denote a permutation.

Find the previous permutation in ascending order.

Notice: The list may contains duplicate integers.

Example

For [1,3,2,3], the previous permutation is [1,2,3,3]

For [1,2,3,4], the previous permutation is [4,3,2,1]

Online Judge