Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

For "aabaabaa", how many indices i >= 1 have Z-function value exactly 2?

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

Correct answer: D. 1

Compute the Z-array with the standard linear algorithm and count entries equal to 2. Entries of 1 and 0 are separate counts.

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

Exams that ask this topic