Data Structures & AlgorithmsHardIBM · Deloitte pattern
What is the length of the longest common subsequence of "AEEBDCCC" and "BEBEADE"?
- A. 3
- B. 4
- C. 6
- D. 2
Correct answer: A. 3
The DP table d[i][j] = d[i-1][j-1]+1 on a match, else max of the two neighbours, gives an LCS length of 3. The edit distance between the same strings is a different quantity, 6.
More Coding Interview Problems questions
- Problem: A string s (length n) must be searched for a pattern p (length m) in text. Which algorithm guarantees O(n+m) worst-case time…
- Problem: Rabin-Karp pattern matching uses a rolling hash to compare a pattern against every window of the text. What is its typical time…
- Problem: Which traversal order is guaranteed to visit nodes level by level in a tree or graph?
- Problem: For a weighted graph with all non-negative edge weights, which algorithm finds shortest paths from a single source, and in what…
- Problem: A graph may contain negative edge weights but no negative cycle. Which single-source shortest path algorithm handles this…
- Problem: What is the time complexity of the Floyd-Warshall algorithm for finding shortest paths between every pair of nodes in a graph…