Data Structures & AlgorithmsHardGATE CS · TCS NQT

How many contiguous substrings of "abcabc" contain exactly 2 distinct letters?

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

Correct answer: B. 5

Count substrings with exactly 2 distinct letters by brute force over all substring positions; the answer is 5, from the length-2 substrings ab, bc, ca, ab and bc.

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

Exams that ask this topic