Data Structures & AlgorithmsVery hardProduct Company SDE · CP practice
What is the length of the longest palindromic subsequence (not substring) of "BBCABABC"?
- A. 5
- B. 3
- C. 4
- D. 8
Correct answer: A. 5
d[i][j] = d[i+1][j−1]+2 if s[i]=s[j], else max(d[i+1][j], d[i][j−1]) → 5 (equals LCS of s and its reverse). The longest palindromic substring has length 3.
More Coding Interview Problems questions
- A function returns the length of the longest strictly increasing subsequence (not necessarily contiguous). What does it return for [15, 1…
- How many subsets (by index, so equal values at different positions count separately) of [1, 3, 3, 5, 1, 5, 9, 5, 1] sum to exactly 11?
- What is the length of the longest palindromic subsequence (not substring) of "BBBBEBBAA"?
- A function returns the length of the longest strictly increasing subsequence (not necessarily contiguous). What does it return for [17…
- How many subsets (by index, so equal values at different positions count separately) of [2, 1, 9, 7, 8, 4, 1] sum to exactly 10?
- A function returns the length of the longest strictly increasing subsequence (not necessarily contiguous). What does it return for [30…