Problem 3720 · Medium

Lexicographically Smallest Permutation Greater Than Target

Keep the longest prefix of target that can be reused, bump the next letter upward, and sort the rest.

Open the interactive visualisation