Data Structures & AlgorithmsHardGATE CS · ICPC regional
What is the smallest positive period p of the string abcabcabca, meaning the smallest p such that s[i] = s[i+p] for every valid i?
- A. 3
- B. 6
- C. 2
- D. 8
Correct answer: A. 3
The smallest period is n minus the longest proper border, and the prefix function gives that border in linear time. For this string the border is the length-7 prefix.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many distinct cyclic rotations does the string abcabc have (rotations are the strings obtained by moving a prefix to the end…
- How many subarrays of [1, 2, 1, 2, 2, 1] read the same forwards and backwards (as sequences of values)?
- What is the length of the longest palindromic substring of xabacdcabay?
- What is the minimum number of cuts needed to partition the string abacdcdad into palindromic pieces?
- How many times does the pattern aba occur in ababababa when occurrences may overlap?
- For the string aabaaabaa, what is the sum of the Z-function values Z[1] + Z[2] + ... + Z[n-1] (Z[i] is the longest common prefix of the…