Data Structures & AlgorithmsModerateTCS NQT · Infosys pattern
What is the length of the longest common subsequence of PLACEMENT and COMPLETE?
- A. 5
- B. 3
- C. 4
- D. 6
Correct answer: C. 4
The DP table (L[i][j] = L[i−1][j−1] + 1 on a match, else the max of the two neighbours) ends at 4. One LCS is C, M, E, T (PLA-C-E-M-E-N-T vs C-O-M-P-L-E-T-E: C, M, E, T appear in order in both); another is P, L, E, T. Five would need, e.g., P L E T E, but PLACEMENT has no E after its T.
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
- Keys 15, 10, 20, 8, 12, 25, 6, 11, 13, 9 are inserted into an empty BST. What is the height of the tree (edges on the longest root-to-leaf…
- Keys 10, 20, 30, 25, 28 are inserted into an empty AVL tree. Which rotations are performed, in order (named by imbalance case)?
- Floyd–Warshall on vertices 0–3 starts from the weight matrix below (∞ = no edge). After the iteration with k = 0 (paths allowed to go…
- How many distinct spanning trees does the graph with vertices A, B, C, D and edges A–B, B–C, C–D, D–A, A–C (a 4-cycle plus one diagonal)…
- A recursive segment tree is built over an array of n = 6 elements (each internal node splits its range into two halves; leaves are single…
- In a Fenwick (binary indexed) tree of size 16 (1-based), the update at index 5 adds the value to i = 5 and then repeatedly does i += i &…