Data Structures & AlgorithmsVery hardProduct Company SDE · Amazon OA

Problem: Remove exactly 3 digits from the number "1432219" to make the smallest possible number (leading zeros are not allowed in the result). What is the resulting number?

  1. A. 1221
  2. B. 2219
  3. C. 1219
  4. D. 1432

Correct answer: C. 1219

A monotonic stack removes a digit whenever the next digit is smaller: 4 (before 3), 3 (before 2), then 2 (before 1), leaving 1219. Removing the three largest digits 4, 3, 9 gives 1221, deleting the first three digits gives 2219, and deleting the last three gives 1432.

More Coding Interview Problems questions

Exams that ask this topic