Data Structures & AlgorithmsVery hardCodeforces Div2 C · TCS NQT

From "bcabcdbac" delete exactly 3 letters (the rest keep their order). What is the lexicographically LARGEST string you can obtain?

  1. A. bcdbac
  2. B. abcbac
  3. C. dcbacb
  4. D. ccdbac

Correct answer: D. ccdbac

Use a monotonic stack that pops a smaller letter whenever a larger one arrives and deletions remain, then trim the tail. Deleting the first k letters ignores the letters that would make the result larger.

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

Exams that ask this topic