Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

What is the lexicographically smallest subsequence of length 3 of "cbacdcbc"?

  1. A. acb
  2. B. abc
  3. C. aba
  4. D. bca

Correct answer: B. abc

Take the smallest letter whose later suffix still leaves enough characters, then repeat with a monotonic stack. Enumerating all length-3 subsequences also settles it.

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

Exams that ask this topic