Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: The string "cbaebabacd" is scanned with windows of length 3. How many windows are anagrams of "abc" (same letters, same counts, any order)?

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

Correct answer: D. 2

Each window is an anagram exactly when its letter counts match the pattern's counts. Checking whether the window contains each letter once is the same test here, but counting distinct letters alone is insufficient in general.

More Coding Interview Problems questions

Exams that ask this topic