Data Structures & AlgorithmsHardProduct-company placement
For the string ABRACADABRA, what are the lengths of the longest palindromic SUBSTRING and the longest palindromic SUBSEQUENCE?
- A. 7 and 7
- B. 3 and 3
- C. 3 and 7
- D. 3 and 8
Correct answer: C. 3 and 7
The substring must be contiguous (expand around centres: 3); the subsequence may skip letters and equals LCS(s, reverse(s)) = 7.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Heap sort (ascending) is run on [20, 37, 49, 16, 22, 10, 31, 33]: build a max-heap bottom-up, then repeatedly swap the root with the last…
- What is the length of the longest BITONIC subsequence (strictly increasing then strictly decreasing; either part may be empty) of [20, 21…
- 0/1 knapsack with capacity 17: items (weight, value) = (9, 21), (6, 19), (3, 9), (7, 13), (3, 27). What is the maximum total value?
- Coins of denominations 1, 6, 9, 10 are available in unlimited supply. What is the minimum number of coins needed to make 33, and how many…
- For the string BBABCBCAB, what are the lengths of the longest palindromic SUBSTRING and the longest palindromic SUBSEQUENCE?
- With 3 identical eggs and at most 5 drops, what is the largest number of floors for which you can always determine the critical floor (the…