Skip to content

Monotone Increasing Digits

MediumGreedy
Decode it first. Clues, constraints, pattern and plan before any code.

A number has monotone increasing digits if each digit is less than or equal to the digit after it (like 1234 or 1129). Return the largest number less than or equal to n with that property.

n = 10    →  9
n = 1234  →  1234
n = 332   →  299

Constraints

  • 0 <= n <= 10^9