You have an grid and a ball at position . 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 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 .