Data Structures & AlgorithmsHardIBM · Deloitte pattern

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

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

Correct answer: C. 3

A window of length 2 is an anagram of "AB" exactly when their character-frequency counts match, not when the characters appear in the same order. Checking every window of "BABAACBCCA" 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