Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT

How many substrings of "cbaebabacd" of length 3 are anagrams of "abc" (contain exactly the same letters with the same counts, in any order)?

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

Correct answer: A. 2

Slide a fixed window of length |p| and keep a letter-count map; each window whose counts equal the pattern's counts is a match. Counting exact occurrences of the pattern string (in the given order) gives a smaller number.

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

Exams that ask this topic