Data Structures & AlgorithmsModerateProduct-company MCQ pattern
A robot moves only right or down on a 3 × 4 grid of cells (3 rows, 4 columns) from the top-left cell to the bottom-right cell. The cell in row 2, column 2 (counting from 1) is blocked. How many paths are there?
- A. 6
- B. 4
- C. 5
- D. 10
Correct answer: B. 4
Without the block there are C(5, 2) = 10 paths. Paths through (2, 2) number C(2, 1) × C(3, 1) = 2 × 3 = 6, so 10 − 6 = 4; the DP table that sets the blocked cell to 0 gives the same.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- What is the length of the longest palindromic SUBSEQUENCE of CHARACTER?
- Coins of 1, 5, 6 and 8 are available in unlimited supply. For amount 11, how many coins does the 'largest coin first' greedy method use…
- Each job takes 1 unit of time; only one job runs at a time. Jobs (deadline, profit): J1 (2, 100), J2 (1, 19), J3 (2, 27), J4 (1, 25), J5…
- Characters a, b, c, d, e occur 4, 7, 9, 12 and 20 times. With an optimal Huffman code, how many bits are needed to encode the whole text?
- Bellman–Ford from A relaxes the directed edges in the fixed order C→D (2), B→C (3), A→B (4), A→C (9), B→D (7). After the FIRST full pass…
- A directed graph has edges 1→2, 2→3, 3→1, 3→4, 4→5, 5→6, 6→4, 6→7, 7→8. How many strongly connected components does it have?