The Monotone Increasing Digits problem asks you to find the largest number less than or equal to a given integer N such that each digit is non-decreasing (i.e., each digit is ≥ the digit before it). For example, 123, 1111, and 45679 are monotone increasing. This Monotone Increasing Digits interview question uses a greedy right-to-left digit scan.
Credit Karma, Amazon, and SAP ask this to test digit manipulation and greedy reasoning. The insight — that when a digit exceeds the next, you decrement it and set everything to the right to 9 — requires careful thinking about how digit changes propagate. The math and greedy interview pattern is directly demonstrated.
Greedy right-to-left scan. Convert the number to a digit array. Scan from right to left: whenever a digit is greater than the next digit, decrement it by 1 and mark all positions to its right as '9'. After the scan, rebuild the number. The mark position tracks where 9s should begin.
N = 332.
N = 1234: already monotone increasing → answer = 1234.
Digit greedy problems often require scanning from right to left to handle cascading effects. The pattern: find the rightmost violation, fix it (decrement), fill everything to the right with 9 (maximum value). This maximizes the number while maintaining the constraint. Practice similar problems like "remove k digits to get smallest number" — they use the same rightward 9-fill / leftward decrement structure with monotone stack variations.