Data Structures & AlgorithmsModerateFlipkart/Uber OA · placement

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

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

Correct answer: A. 3

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

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

Exams that ask this topic