Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D
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 shortest paths exist from (0,0) to (3,3)?
- A. 3
- B. 1
- C. 2
- D. 4
Correct answer: C. 2
BFS that accumulates path counts only along edges into the next layer counts shortest paths exactly. Counting all paths, including longer detours, is a different (and much larger) quantity.
More Coding Interview Problems questions
- 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…
- Problem: Insert the words "car", "cat", "care", "dog", "do", "dot" into an empty trie (one node per character, root has no letter). How…
- Problem: Count the occurrences of the pattern "aba" in "abababa", where occurrences may overlap.