Back to problems

Second Largest Permutation From Given Multiset

Algorithm · Meta · Medium

Coding: Find the Next-to-Maximum Permutation of a Multiset You receive an integer array nums, whose values are allowed to repeat. Rearrange its elements in every possible unique way, and compare the resulting sequences lexicographically. Produce the distinct permutation immediately below the lexicographically greatest one: it must be smaller than the maximum permutation, while no other distinct permutation lies between them. When a second unique arrangement does not exist,…

Checking your access…