Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: For the words ["flowchart", "flow", "flight", "flower"], what is the length of their longest common prefix?
- A. 2
- B. 3
- C. 1
- D. 4
Correct answer: A. 2
Shrink the candidate prefix until every word starts with it. Comparing only the first two words gives a longer, incorrect prefix.
More Coding Interview Problems questions
- Problem: In the string "abciiidef", what is the maximum number of vowels (a, e, i, o, u) in any contiguous substring of length 4?
- Problem: What is the minimum number of insertions plus deletions needed to convert "heap" into "pea" if only insertions and deletions are…
- Problem: How many binary strings of length 8 have no two consecutive 1s and begin with the digit 0?
- Problem: A 0/1 knapsack has capacity 10 and items (weight, value): (5, 10), (4, 40), (6, 30), (3, 50). What is the maximum total value?
- Problem: The longest bitonic subsequence (first strictly increasing, then strictly decreasing, either part may be empty) of [1, 11, 2, 10…
- Problem: Find the minimum path sum from the top to the bottom of the triangle [[2], [3, 4], [6, 5, 7], [4, 1, 8, 3]], moving to an…