Data Structures & AlgorithmsVery hardCodeforces Div2 B-D · ICPC regional

From the digit string "1432219" remove exactly 3 digits (keeping the remaining digits in their original order) so that the resulting number is as small as possible. What is the result (without leading zeros)?

  1. A. 1219
  2. B. 12199
  3. C. 1322
  4. D. 1229

Correct answer: A. 1219

A monotonic stack removes a previous digit whenever a smaller digit arrives, while deletions remain. Removing the first three digits instead gives 2219, which is larger than 1219.

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

Exams that ask this topic