Data Structures & AlgorithmsVery hardProduct Company SDE · CP practice
What is the length of the longest palindromic subsequence (not substring) of "BDDDACBBD"?
- A. 15
- B. 5
- C. 4
- D. 6
Correct answer: B. 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 [4, 7…
- What is the length of the longest common subsequence of "ABCDBEBC" and "CECCBBAAD"?
- A function returns the length of the longest strictly increasing subsequence (not necessarily contiguous). What does it return for [17, 4…
- What is the length of the longest common subsequence of "ECCCCBADC" and "EBDBECB"?
- What is the Levenshtein edit distance (insert, delete, substitute all cost 1) between "DAABDB" and "BCDCEBDB"?
- Problem: 7 servers are joined by cables one at a time. Count the connected groups at the end and how many cables were redundant (joined…