Data Structures & AlgorithmsHard

How many contiguous substrings of length exactly 4 in "abcadbcde" consist of four DISTINCT characters?

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

Correct answer: D. 4

Slide a window of length 4 and check distinctness with a count map or a set; each step changes one character in and one out. Counting the complement or windows of length 3 answers a different question.

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

Exams that ask this topic