Data Structures & AlgorithmsHardGATE CS · ICPC regional
Among all cyclic rotations of "bcabca" (there are n = 6 of them, including the original), what is the 0-based index i of the lexicographically smallest rotation s[i..] + s[..i]? If several are equal, take the smallest index.
- A. 3
- B. 2
- C. 1
- D. 4
Correct answer: B. 2
Compare all rotations, or use Booth's algorithm (O(n)) on s + s. The smallest index among equal minima matters here, and the rotation starting at the smallest letter is not always the smallest rotation.
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 minimum number of characters that must be inserted at the FRONT of "abaccabb" to make the whole string a palindrome?
- How many contiguous subarrays of [3, 4, -7, 1, 3, 3, 1, -4, 2] have sum exactly 7? Negative numbers are present.
- In "swissmississippi", what is the 0-based index of the first character that appears exactly once in the whole string?
- What is the length of the longest substring of "eceeebbaccbbaaceddccc" that contains AT MOST two distinct letters?
- In the list ['listen', 'silent', 'enlist', 'google', 'gooegl', 'cat', 'act', 'tac', 'dog'], how many unordered pairs of different…
- How many index pairs (i < j) of the list [1, 3, 2, 3, 4, 5, 3, 1, 2, 5] satisfy a[i] + a[j] = 6? Equal values at different positions count…