Data Structures & AlgorithmsHardProduct Company SDE · Infosys OA
Problem: The longest common subsequence of "ABCBDAB" and "BDCABA" has length L. What is L?
- A. 5
- B. 3
- C. 4
- D. 6
Correct answer: C. 4
The LCS table takes the diagonal plus one on a match and the maximum of its neighbours otherwise. Using the longest common substring (contiguous) instead gives a smaller value.
More Coding Interview Problems questions
- Problem: From the string "aaabbbaabbccaa", you may delete the minimum number of characters so that no two adjacent characters are equal…
- Problem: A stack-based reduction processes the string "abbaca" from left to right: if the current character equals the top of the stack…
- Problem: Bubble sort is run on [5, 2, 9, 1, 7, 3, 8, 6, 4] using the standard adjacent-swap pass (for i from 0 to n−2, swap a[j] and…
- Problem: A list starts as [1, 2, 3, 4, 5, 6, 7, 8]. Four operations are applied in order: rotate the list left by 3; reverse the first 4…
- Problem: XOR of all integers from l = 13 to r = 46 inclusive. Compute the result.
- Problem: The number of trailing zeros of 500! written in base 6 (i.e., how many times 6 divides 500!) is what value?