Data Structures & AlgorithmsHardCodeforces Div2 B-D · ICPC regional
How many distinct strings appear among the rotations of "abab" (all n cyclic shifts, including the unshifted string)?
- A. 2
- B. 4
- C. 3
- D. 1
Correct answer: A. 2
Periodic strings have fewer distinct rotations than their length: "abab" has period 2, so its 4 rotations collapse to 2 distinct strings. Naively reporting n is the trap.
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 "aaabbbcaabbbcc" in which every letter occurring in it appears at least 3 times?
- How many contiguous subarrays of [1, 2, 3, 3, 2, 1, 4] have a bitwise XOR of exactly 0?
- Among pairs of distinct elements of [-8, -3, 1, 5, 9, 12], which pair sum is closest to the target 4? (Report the sum itself.)
- What is the sum of the minimum element over all contiguous subarrays of [5, 3, 1, 4, 2]?
- What is the area of the largest rectangle containing only 1s in the binary matrix whose rows are 1101, 1111, 0111 and 1110?
- A grid has rows ..#. / .##. / .... / #.#. where '.' is free and '#' is a wall. Moving up, down, left or right one cell at a time, what is…