Warehouse Shelf Stacking - Problem
You are managing a warehouse where items need to be collected from shelves arranged in a grid. Each cell in the grid represents a shelf with a specific number of items that can be picked up.
Starting from the top-left corner (position [0,0]), you need to reach the bottom-right corner while collecting the maximum possible number of items. You can only move right or down at each step.
Given a 2D grid shelves where shelves[i][j] represents the number of items on shelf at position [i,j], return the maximum number of items you can collect on your path from top-left to bottom-right.
Input & Output
Example 1 — Basic 2x3 Grid
$
Input:
shelves = [[1,3,1],[1,5,1]]
›
Output:
10
💡 Note:
Path: (0,0)→(0,1)→(1,1)→(1,2) collecting 1+3+5+1 = 10 items. This is better than going (0,0)→(1,0)→(1,1)→(1,2) which gives 1+1+5+1 = 8 items.
Example 2 — Single Row
$
Input:
shelves = [[1,2,3,4]]
›
Output:
10
💡 Note:
Only one path possible: move right through all cells collecting 1+2+3+4 = 10 items.
Example 3 — Single Column
$
Input:
shelves = [[1],[2],[3]]
›
Output:
6
💡 Note:
Only one path possible: move down through all cells collecting 1+2+3 = 6 items.
Constraints
- 1 ≤ shelves.length ≤ 200
- 1 ≤ shelves[i].length ≤ 200
- 0 ≤ shelves[i][j] ≤ 100
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code