Data Structures & AlgorithmsHardFlipkart/Uber OA · placement

A fixed window of length 3 slides over s = "bcaacbccbbbbac" with a character-count array. At how many starting positions is the window an anagram (permutation) of "aac"?

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

Correct answer: D. 2

Compare the window's letter counts with those of "aac" at each of the 12 positions, updating the counts in O(1) per slide. Matching windows: 2; exact copies of the pattern: only 1.

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

Exams that ask this topic