Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
A grid has 3 rows and 4 columns with these values (top to bottom): 6389 5169 6136 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. 4
- B. 5
- C. 6
- D. 3
Correct answer: B. 5
A memoised DFS from every start gives 5 cells. Restricting moves to right and down gives 3, 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 directed acyclic graph has the vertices F, H, M, P, U, W and the arcs H→M, H→W, U→F, F→M, F→P, F→W, M→P, M→W. Two players alternately…
- An undirected graph has the vertices A, D, U, W, Y and the edges U–Y, A–D, A–Y, D–Y, W–Y, U–D, A–W, A–U. How many simple cycles does it…
- Floyd–Warshall runs on vertices 1 to 5 with these arcs u→v (weight): 1→2 (6), 1→3 (5), 1→5 (6), 2→3 (5), 2→4 (11), 3→1 (11), 3→2 (3), 3→4…
- An undirected graph on 6 vertices has the edges E–Z, E–K, E–W, Z–K, Z–F, Z–H, Z–W, K–F, K–W. How many simple paths (no repeated vertex) go…
- A directed graph with no directed cycles has arcs u→v (weight) : T→C (8), T→G (-3), T→L (5), C→G (1), C→X (-1), C→L (5), G→X (-3), X→L…
- A directed acyclic graph has the vertices A, B, D, G, H, I, L and the arcs H→G, H→D, H→B, H→I, H→L, A→G, A→D, A→B, A→I, A→L, G→D, G→B…