Data Structures & AlgorithmsVery hardProduct Company SDE · ICPC regional
Problem: A 3×4 grid holds entry costs (row by row): [[1, 3, 1, 2], [1, 5, 1, 9], [4, 2, 1, 1]]. Starting at the top-left cell, you may move up, down, left or right, and each move costs the value of the cell you enter. The start cell's value is not paid. What is the minimum total cost to reach the bottom-right cell?
- A. 7
- B. 8
- C. 5
- D. 22
Correct answer: A. 7
Dijkstra on entry costs finds 7, entering 3, 1 along the top row, then 1, 1 down column 2 and 1 into the corner; a right/down DP agrees here. Also paying for the start cell gives 8, counting moves gives 5, and always stepping to the cheapest unvisited neighbour wanders into expensive cells (22).
More Coding Interview Problems questions
- Problem: A directed graph on vertices 0–7 has arcs 0→1, 0→2, 1→3, 2→3, 3→4, 4→5, 2→6, 6→7. How many vertices are reachable from vertex 0…
- Problem: A 4×4 grid has obstacles at (1,1), (1,2), (2,1) (row, column, 0-indexed). Movement is up, down, left or right. How many distinct…
- Problem: An undirected graph on 9 vertices (0–8) has edges 0-1, 1-2, 3-4, 4-5, 5-3, 6-7. Vertex 8 is isolated. Count the unordered pairs…
- Problem: A rooted tree (root 1) has children lists: 1: [2, 3, 4], 2: [5, 6], 3: [], 4: [7], 5: [], 6: [8, 9], 7: [], 8: [], 9: []. How…
- Problem: A tree has nodes 1–6 with weighted edges 1-2 (3), 1-3 (5), 2-4 (4), 2-5 (2), 3-6 (7). What is the weighted diameter (maximum over…
- Problem: A rooted tree (root 1) with children: 1: [2, 3], 2: [4, 5], 3: [6], 4: [7], 5: [], 6: [], 7: []. Children are visited in…