Data Structures & AlgorithmsHardProduct Company SDE · Infosys OA
Problem: What is the length of the longest common substring (contiguous) of "abcdxyz" and "xyzabcd"?
- A. 5
- B. 3
- C. 6
- D. 4
Correct answer: D. 4
Check the contiguous match starting at each pair of positions and keep the longest. Taking the longest common subsequence instead gives a larger value, since the subsequence need not be contiguous.
More Coding Interview Problems questions
- Problem: From the array [3, 2, 7, 10], choose a subset with no two adjacent indices chosen, maximising the sum. What is the maximum sum?
- Problem: The array [5, 1, 6, 2, 7] must be made strictly increasing by deleting the fewest elements. What is the minimum number of…
- Problem: On the complete graph K4 (vertices 0–3, every pair adjacent), how many walks of exactly 4 edges start at vertex 0? A walk may…
- Problem: Lomuto partition uses the last element as the pivot on [3, 8, 2, 5, 1, 4, 7, 6]. After one partition pass, at what index…
- Problem: Five numbers 1, 2, 3, 4, 5 are inserted in that order into an initially empty min-heap (array form, sift-up after each…
- Problem: Binary search for the value 77 in the sorted list 1, 2, ..., 100 uses the midpoint mid = (lo + hi) // 2 and the inclusive range…