Back to problems

Lexicographically Minimal BoxIds via +1/9 Op

Algorithm · Amazon · Hard

Requirements A move chooses an index i, removes boxIds[i], then places min(boxIds[i] + 1, 9) back at any location. You may perform this action any number of times, including not at all. Produce the lexicographically minimum string achievable without changing the string length. Constraints: 1 <= boxIds <= 2 * 10^5; boxIds contains only digits from 0 through 9; zero may appear at the front. Examples The result is smallest because moving the larger digits out of the way lets…

Checking your access…