Data Structures & AlgorithmsHardCodeforces Div 2 D · ICPC regional
A grid has 3 rows and 4 columns with these values (top to bottom): 4179 9341 9892 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. 5
- B. 4
- C. 7
- D. 6
Correct answer: A. 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
- Two unmarked jugs hold 4 litres and 5 litres. Allowed operations: fill a jug completely, empty a jug completely, or pour one jug into the…
- A directed graph has the vertices J, K, L, R, W and the arcs W→K, W→L, W→J, K→W, K→L, K→R, L→W, L→K, L→J, J→L, R→K, R→J. Count the…
- The directed acyclic graph has the vertices C, I, J, R, Y, Z and the arcs C→R, Z→J, R→Y, I→Z, Z→Y, C→Y, Z→C, Y→J, I→C, I→J, Z→R, R→J. How…
- A four-wheel combination lock shows four digits 0–9 on wheels that wrap around (9 goes to 0 and 0 goes to 9). One move turns one wheel by…
- A bipartite graph has left side P1, P2, P3, P4 and right side Q1, Q2, Q3, Q4, Q5, with edges P1–Q1, P3–Q1, P3–Q5, P1–Q5, P2–Q3. What is…
- A connected undirected graph has the vertices A, E, G, J, P, Q, Z and the edges Z–P, Z–J, Z–E, Z–A, P–J, P–G, J–E, A–Q. How many bridges…