Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

For "abacabad", how many indices i (0-indexed) have prefix-function value pi[i] equal to 0?

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

Correct answer: D. 4

The prefix-function value is 0 exactly when no proper border ends at index i; check each index with the failure chain. Each index is checked against all proper borders ending there.

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

Exams that ask this topic