Data Structures & AlgorithmsModerateGATE CS · TCS NQT
How many DISTINCT strings are produced by taking all cyclic rotations of "abcabcab" (including the original)?
- A. 8
- B. 3
- C. 10
- D. 9
Correct answer: A. 8
Rotations are indexed by the starting position, but a periodic string repeats rotations. If the string is a power of a shorter block of length d (so d divides n), only d rotations are distinct. Counting all n starting positions overcounts such periodic strings.
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
- Process [3, 1, 4, 1, 5, 9, 2, 6] with a stack: before pushing each value, pop while the top is smaller than it. How many pop operations…
- From the number 1, the allowed moves are x -> x+1, x -> x-1 and x -> 2x, staying within [1, 40]. What is the minimum number of moves to…
- In the list [1, 3, 4, 7, 2, 9], how many nodes come strictly before the first node whose value exceeds 5?
- How many index pairs i < j in [3, 5, 6, 1] satisfy a[i] XOR a[j] < a[i]?
- How many pairs of positions i < j in the string aabbab have s[i] = a and s[j] = b (the letters need not be adjacent)?
- What is the sum of the prefix-function values pi[0] through pi[n-1] of the string abacabab?