Data Structures & AlgorithmsHardGATE CS · TCS NQT
A string is compared to a pattern by repeatedly rotating its first character to the end. How many distinct rotations of abab exist (identity included)?
- A. 3
- B. 1
- C. 2
- D. 4
Correct answer: C. 2
abab has period 2, so rotations 0 and 2 coincide, and rotations 1 and 3 coincide. Counting every index as distinct gives four.
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
- What is the length of the longest substring of abcabdabcd that contains at most two distinct characters?
- How many pairs of distinct positions (i, j) with i < j in the string abcdcba satisfy s[i] = s[j]?
- In the sequence of queue operations enqueue 5, enqueue 3, dequeue, enqueue 8, dequeue, dequeue, enqueue 1, what is the value at the front…
- For the pattern "aabaabaaab" (0-based), what is the value of the KMP prefix function π at the LAST index? π[i] is the length of the…
- How many times does the pattern "aaa" occur in the text "aaaabaaaaab", counting OVERLAPPING occurrences (occurrences may share letters)?
- Using the Z-function (z[i] = length of the longest common prefix of s and s[i..], with z[0] = n), what is the sum of all z-values of…