~/problems
Problems
Basics first, then the classics, then company-style assessments. Every problem has tests you run right here; multi-level ones unlock as you go. See the roadmap.
Grid DP
dp[r][c] from neighbours; add a dimension for extra state (jumps left).
Main path: 8 problems, about 4 hours.
Notes
Recognise it when: paths through a grid with right/down moves and max or min or count.
dp[r][c] = grid[r][c] + best(dp[r-1][c], dp[r][c-1])
Extra constraints get extra dimensions: dp[r][c][j] = best score having used j jumps (or keys, or skips). Transitions: normal moves keep j; special moves go from j-1.
Gotchas
- Initialize unreachable states to
-inf, not 0, especially with negative cells. - The answer is
maxover all j, because using the extra moves is optional.
11 problems
Interview roadmap
2-D dynamic programming Grids, two strings, knapsacks, ranges.
Grid DP guide
- Play first: The Castle Road 1-minute game Grid dynamic programming
- Can you reach the corner? basics py · c++ · java easy
- Unique Paths code the boss 2 levels py · c++ · java medium
- Minimum Path Sum py · c++ · java medium
- Minimum Falling Path Sum py · c++ · java medium
- Mushroom walks with an exact haul py · c++ · java medium
- Robots matching a sensor reading Uber py · c++ · java medium
- Longest Increasing Path in a Matrix py · c++ · java hard
- Max-score grid path with limited jumps assessment 4 levels OpenAI py · c++ · java hard
More practice: 3 problems
- Maximal Square py · c++ · java medium
- Knight stays on the board py · c++ · java medium
- Minimum Falling Path Sum II py · c++ · java hard