Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B
A grid has 4 rows and 4 columns with these values (top to bottom): 7416 6762 2894 3773 A path moves between side-adjacent cells (up, down, left or right) and each next cell must have a strictly larger value than the current cell. What is the largest number of cells on such a path?
- A. 7
- B. 6
- C. 5
- D. 4
Correct answer: C. 5
A memoised DFS from every start gives 5 cells. Restricting moves to right and down gives 4, and allowing equal values (non-decreasing paths) gives 4.
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
- A connected undirected graph has the vertices F, I, L, R, S, W, Z and the edges R–S, R–I, R–W, S–L, S–Z, I–F, L–Z. Parallel edges are…
- An undirected graph on 7 vertices has the edges U–Z, U–B, U–J, Z–G, Z–N, G–P, P–B, P–N, P–J, N–J. How many simple paths (no repeated…
- A connected undirected graph has the vertices A, D, J, M, S, Z and the edges M–Z, Z–S, Z–J, Z–A, S–D, S–A, D–A. How many bridges does it…
- A flow network has source S and sink T, with directed arcs and capacities in brackets: S→E (4), S→T (9), C→D (8), C→T (3), B→E (6), B→T…
- A tree has the vertices A, E, G, I, K, L, N, O, W and the edges G–W, W–O, O–E, E–L, G–I, G–A, A–K, O–N. A centroid is a vertex whose…
- A tree has vertices A, B, F, H, I, K, M, Q, S and weighted edges (weights in brackets): Q–S (5), Q–M (4), Q–K (1), S–H (3), Q–A (7), K–B…