Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
What is the length of the longest proper prefix of abcab that is also a suffix of abcab (the border)?
- A. 3
- B. 4
- C. 5
- D. 2
Correct answer: D. 2
The border is ab, which is both the prefix and the suffix; the prefix function gives it directly. A proper prefix excludes the whole string.
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 number of occurrences of the pattern abab in the string ababababab, counting overlapping matches?
- How many binary strings of length 5 contain no two consecutive zeros?
- What is the lexicographically smallest string obtainable from cbad by swapping exactly one pair of characters?
- How many integers x in [1, 100] are divisible by 3 and have a reversed digit string also divisible by 3?
- What is the sum of all divisors of 36 (sigma function)?
- How many unordered pairs {a, b} with 1 <= a < b <= 12 have a + b divisible by 4?