Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

In the text "aaabaaaabaaa", count the occurrences of "aaa" whose starting index is a prime number (0-indexed).

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

Correct answer: B. 1

Find all occurrences of the pattern first (overlapping ones included), then keep only the prime start indices. The total occurrence count without the prime filter is a different answer.

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

Exams that ask this topic