Skip to content
Decoder

Monotone Increasing Digits

Medium

Problem

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.

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

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.