Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

What is the smallest period p (1 <= p < n) of the string "abcabcabca" such that s[i] = s[i + p] for all valid i?

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

Correct answer: B. 3

The block abc repeats, and n - pi[n-1] = 10 - 7 = 3 gives the smallest period. Periods 2, 4 and 5 fail on some position.

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

Exams that ask this topic