Data Structures & AlgorithmsHardLeetCode-style · TCS NQT

Split "ababcbacadefegdehijhklij" into the maximum number of contiguous pieces so that each letter appears in at most one piece. What is the LENGTH of the first piece?

  1. A. 7
  2. B. 3
  3. C. 9
  4. D. 12

Correct answer: C. 9

Record each letter's last index; extend the current piece to the largest last index seen so far and cut when the scan reaches it. Cutting at the first repeat of any letter gives too many pieces.

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

Exams that ask this topic