Data Structures & AlgorithmsModerate

In the string "cbaebabacd", how many substrings of length 3 are ANAGRAMS of "abc" (same letters, any order)?

  1. A. 2
  2. B. 0
  3. C. 4
  4. D. 6

Correct answer: A. 2

A fixed window of length 3 is an anagram when its letter counts equal those of the pattern; each slide updates two counts. Requiring the exact string 'abc', using length 2, or testing only distinctness changes the set.

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

Exams that ask this topic