Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: A matrix stores the number of paths in a 3×3 grid where each cell can be entered from the left or from above, and blocked cells contain 0. Blocked cells are (0,1) and (2,1). How many paths reach the bottom-right cell (2,2) from (0,0)?
- A. 2
- B. 0
- C. 3
- D. 1
Correct answer: D. 1
Path DP with blocked cells set to 0 by skipping them. A blocked cell in row 0 cuts off every route that would pass through it.
More Coding Interview Problems questions
- Problem: The string "racecar" has length 7. How many of its substrings are palindromes with length at least 3? Count index ranges.
- Problem: Count the pairs (i, j) with i < j in the array [1, 5, 2, 8, 3, 5] whose absolute difference is at most 2.
- Problem: A dice-throwing game: starting at 0, each throw adds a value from 1 to 6, and the player stops as soon as the total is at least…
- Problem: Dijkstra is run on a directed graph with arcs 0→1 (5), 0→2 (2), 2→1 (1), 1→3 (2), 2→3 (7), 3→4 (1), 2→4 (9). Each vertex is…
- Problem: A directed graph on vertices 0–4 has arcs 0→1, 1→2, 2→0, 2→3, 3→4. How many distinct simple directed cycles does it contain?
- Problem: An undirected graph on 6 vertices has edges 0-1, 1-2, 2-3, 3-0, 3-4, 4-5. Find the number of vertices whose removal leaves a…