Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 D
What is the length of the longest proper border of "abacabacabab"? A border is a non-empty proper prefix that is also a suffix.
- A. 2
- B. 10
- C. 4
- D. 8
Correct answer: A. 2
A border of length b means the prefix and suffix of length b match. The KMP prefix function at the last index gives the longest proper border directly; the smallest period is the complementary quantity n minus the border.
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
- Array [2, 3, 1, 4, 2, 5, 1, 2]: from index i you may jump to any index j with i < j ≤ i + a[i]. Landing on index j costs a[j]. Starting at…
- How many strictly increasing sequences of length 4 can be formed from the values 1 to 10 (each sequence uses four distinct values, listed…
- The sorted array [1, 2, 4, 5, 9, 10] is given. What is the smallest positive integer that does NOT appear in it?
- How many DISTINCT strings are produced by taking all cyclic rotations of "abcabcab" (including the original)?
- 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…