Data Structures & AlgorithmsVery hardTCS NQT · Infosys pattern

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

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

Correct answer: B. 4

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 "BABAAABCC" this way gives 4 matches, versus only 2 if exact substring equality (same order) were required instead.

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

Exams that ask this topic