Dynamic Programming21 sections · 916 units
Open in Course

LeetCode 576 Out of Boundary Paths - Problem Statement

LeetCode 576

You have an m×nm \times n grid and a ball at position (startRow,startCol)(startRow, startCol). You can move the ball in 4 directions (up, down, left, right). Find the number of paths to move the ball out of the grid boundary in exactly maxMovemaxMove moves or fewer. This is counting paths, not computing probability.

But the structure is identical: state is (position, moves remaining), transitions go to 4 neighbors. The twist: paths that go off-grid count toward the answer instead of returning 00.