Data Structures & AlgorithmsHardProduct Company SDE · Amazon/Microsoft-style OA

Problem: How many windows of length 3 in the text "bacacbaab" are anagrams of the pattern "aab" (same letters with the same multiplicities, any order)?

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

Correct answer: D. 2

Sliding-window multiset comparison: a window is an anagram iff its letter counts equal the pattern's counts. Checking only that the window contains the same set of letters ignores multiplicities.

More Coding Interview Problems questions

Exams that ask this topic