Data Structures & AlgorithmsVery hardProduct-company MCQ pattern

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

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

Correct answer: C. 3

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

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

Exams that ask this topic