Data Structures & AlgorithmsVery hardProduct-company MCQ pattern

Using a sliding window of fixed size with a character-frequency count, how many substrings of "CBCAACACBABCB" are anagrams of "CAB"?

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

Correct answer: C. 4

A window of length 3 is an anagram of "CAB" exactly when their character-frequency counts match, not when the characters appear in the same order. Checking every window of "CBCAACACBABCB" this way gives 4 matches, versus only 0 if exact substring equality (same order) were required instead.

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

Exams that ask this topic