Data Structures & AlgorithmsVery hardGATE CS · TCS NQT
How many distinct cyclic rotations does the string abcabc have (rotations are the strings obtained by moving a prefix to the end, including the identity)?
- A. 4
- B. 3
- C. 2
- D. 6
Correct answer: B. 3
Rotations starting at i and i+3 coincide because the string has period 3, so only 3 distinct rotations remain. Counting all six index shifts overcounts.
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 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…
- How many distinct substrings of length 3 does the string abcabcabd have?