Data Structures & AlgorithmsModerateCodeforces Div2 C · TCS NQT
What is the length of the longest palindromic substring of "bananaracecarbnn"?
- A. 3
- B. 8
- C. 7
- D. 14
Correct answer: C. 7
Expand around each centre (for odd and even lengths) and keep the largest palindrome; Manacher's algorithm does this in O(n). Restricting to palindromic subsequences or counting distinct palindromes answers a different question.
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
- Apply the reversal of the first 4 elements to the queue 1, 2, 3, 4, 5, 6, 7, 8 (front first). What is the element at position 6 of the…
- For the array [1, 3, 2, 4], take the next strictly greater element of each position (-1 if none) and sum these values, ignoring the -1…
- What is the sum of the minimum of every contiguous window of length 2 in the array [3, 1, 4, 1, 5, 9, 2, 6]?
- A singly linked list contains the people 1 to 12 in a circle. Starting from person 1, every 4th person is removed (the count starts at 1)…
- How many contiguous subarrays of [3, 4, -7, 1, 2, -6] have a sum of exactly zero?
- In the array [1, 4, 6, 8, 13], the minimum absolute difference between two distinct elements is d. How many index pairs i < j have |a[i]…