Monotone Increasing Digits
I had tried solving this problem few years back, failed. Took a look at the hint, and if you follow the hint, you'll solve it too. Here is the problem: Monotone Increasing Digits - LeetCode 738. Monotone Increasing Digits Medium 771 81 Add to List Share An integer has monotone increasing digits if and only if each pair of adjacent digits x and y satisfy x <= y . Given an integer n , return the largest number that is less than or equal to n with monotone increasing digits . Example 1: Input: n = 10 Output: 9 Example 2: Input: n = 1234 Output: 1234 Example 3: Input: n = 332 Output: 299 Constraints: 0 <= n <= 10 9 Accepted 34,146 Submissions 73,531 And here was the hint: " Build the answer digit by digit, adding the largest possible one that would make the number still less than or equal to N. " This is exactly how the solution was implemented. Since we're looking at the increasi...