Algorithm · Oracle · Medium
Requirements For a nonnegative integer n, determine the greatest value that is no larger than n and has digits in nondecreasing order from left to right, meaning each digit is at most the digit immediately following it. Examples Input: n = 421 Output: 399 Explanation: The pair 4, 2 violates the required ordering. Lowering 4 to 3 and making the remaining positions 9 produces 399, whose digits are nondecreasing. Input: n = 678 Output: 678 Explanation: Its digits already…
Checking your access…