Data Structures & AlgorithmsModerateGATE CS · TCS NQT

How many substrings of length 2 in the string abcabcab occur at least twice in the string (possibly overlapping)?

  1. A. 4
  2. B. 3
  3. C. 2
  4. D. 5

Correct answer: B. 3

Count the occurrences of each length-2 substring in a hash map. Here ab, bc and ca each appear at least twice, and cb, ba do not appear at all.

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

Exams that ask this topic