The Find the Maximum Number of Fruits Collected coding problem presents a grid where three children start at different positions:
Bloomberg uses this "Hard" problem to test your ability to decompose a complex problem into independent sub-problems. Since the paths of the three children are restricted to non-overlapping regions (diagonal, above-diagonal, below-diagonal), their collections are independent. It evaluation your mastery of Matrix Dynamic Programming and your ability to define valid movement rules.
This is a Matrix Dynamic Programming problem.
grid[i][i].dp[i][j] is the max fruits reaching cell from the top-right. Moves allowed are usually .Sum(Diagonal) + DP_Above(n-1, n-1) + DP_Below(n-1, n-1).Grid :
(0,0), (1,1), (2,2).(0,1), (0,2), (1,2).(1,0), (2,0), (2,1).
Since they never cross into each other's territory, we simply solve the "Max path in a triangle" DP twice and add the diagonal sum.When you see multiple "actors" in a grid, check if their available moves allow them to ever visit the same cell. If not, the problem is just multiple independent DP problems combined at the end.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Minimum Falling Path Sum II | Hard | Solve | |
| Cherry Pickup II | Hard | Solve | |
| Dungeon Game | Hard | Solve | |
| Check if There Is a Valid Parentheses String Path | Hard | Solve | |
| Cherry Pickup | Hard | Solve |