Data Structures & AlgorithmsModerateTCS NQT · Infosys
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 adjacent entry in the next row at each step.
- A. 21
- B. 15
- C. 11
- D. 16
Correct answer: C. 11
Bottom-up, each entry adds the smaller of its two children: the best path is 2 → 3 → 5 → 1 = 11. Using max instead of min gives 21, always going straight down the left edge gives 15, and a top-down DP that reads the last bottom cell instead of the row minimum gives 16.
More Coding Interview Problems questions
- Problem: The message "2261" is decoded by mapping 1→A, ..., 26→Z. Each decoding splits the digits into groups of one or two digits, each…
- Problem: 23 people stand in a circle numbered 1 to 23. Starting at person 1, every second person is eliminated (counting around the…
- Problem: Eight cards labelled 1 to 8 are in a row. A perfect out-shuffle splits the deck into two equal halves (1–4 and 5–8) and…
- Problem: Lamps 1 to 20 are all off. For each pass i = 1 to 20, every lamp whose number is a multiple of i is toggled. How many lamps are…
- Problem: Count integers from 1 to 100 that are divisible by 3 or by 5 but not by 15.
- Problem: Compute 2^(2^5) mod 1000 (that is, 2 raised to the power 32, taken modulo 1000).