Data Structures & AlgorithmsHardProduct Company SDE · ICPC regional
Problem: Starting from an empty tree of directed edges, a DAG has edges 0→1, 0→2, 1→3, 2→3, 2→4, 3→5, 4→5, 1→4. How many distinct directed paths go from vertex 0 to vertex 5?
- A. 5
- B. 4
- C. 3
- D. 6
Correct answer: B. 4
Path counting on a DAG is a memoised sum over out-neighbours. Counting only the shortest paths, or counting vertices reachable, gives different values.
More Coding Interview Problems questions
- Problem: An MST is built with Kruskal's algorithm on vertices 0–4 and edges: 0-1 (4), 0-2 (1), 1-2 (2), 1-3 (5), 2-3 (8), 3-4 (3), 2-4…
- Problem: How many pairs (i, j) with i < j in the array [4, 8, 1, 5, 9, 2, 7, 3, 6] satisfy a[j] − a[i] = 3?
- Problem: How many contiguous subarrays of [7, 2, 9, 4, 1, 8, 3, 5, 6, 10] have a sum divisible by 7?
- Problem: Floyd–Warshall is run on 4 vertices with directed edges 0→1 (3), 1→2 (4), 0→2 (9), 2→3 (1), 3→0 (2), 1→3 (5). Unreachable pairs…
- Problem: On a 6×6 grid, a robot starts at the top-left corner and moves only right or down to the bottom-right corner. The cells (1,2)…
- Problem: Place 4 non-attacking rooks on a 4×4 board (no two share a row or column) such that none is on a forbidden cell. Forbidden cells…