Data Structures & AlgorithmsVery hardTCS NQT · Infosys

How many substrings of abcdabcabd are anagrams of the pattern abd (same letters with the same multiplicities)?

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

Correct answer: A. 2

Use a fixed-size window of length 3 and compare sorted letters or counts. A window with the right letters in the wrong order still counts.

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

Exams that ask this topic