Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D
What is the length of the longest common prefix of the two strings obtained by taking all cyclic rotations of "banana" and keeping only the two lexicographically SMALLEST distinct rotations?
- A. 3
- B. 1
- C. 0
- D. 4
Correct answer: B. 1
Sort the distinct rotations, take the two smallest, and measure their common prefix character by character. Comparing the first two cyclic shifts in position order instead of sorted order gives a different pair.
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
- Count the NON-EMPTY subsets of the 12 items 3 5 6 7 2 9 4 8 1 10 11 12 (chosen by position) whose sum is divisible by 4.
- How many NON-EMPTY subsequences of 1 2 3 5 6 8 9 (subsets chosen by position) have (maximum − minimum) ≤ 2?
- How many NON-EMPTY subsequences of 2 3 4 5 6 8 (position subsets) have a product congruent to 1 modulo 7?
- How many subsequences of EXACTLY three elements of 1 2 3 4 5 6 7 8 (chosen by position) have an EVEN sum?
- In the string "aabbaab", how many pairs of positions i < j form the subsequence 'ab' (S[i] = 'a' and S[j] = 'b')?
- How many index triples i < j < k in "aabbccabc" spell the subsequence 'abc' (characters need not be adjacent)?