Data Structures & AlgorithmsHardCodeforces Div2 B · TCS NQT

From the number 1432219 you must delete exactly 3 digits (the remaining digits keep their order). What is the smallest number you can obtain, written without leading zeros?

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

Correct answer: C. 1219

Use a monotonic stack: while the top digit is larger than the current digit and deletions remain, pop it. Deleting the first k digits or the largest digits one at a time misses the case where a smaller digit appears later.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic