
Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Is traversing every path feasible? There are many possible paths for a small matrix. Try to optimize it.
Can we use some space to store the number of paths and update them after every move?
One obvious thing: the ball will go out of the boundary only by crossing it. Also, there is only one possible way the ball can go out of the boundary from the boundary cell except for corner cells. From the corner cell, the ball can go out in two different ways. Can you use this thing to solve the problem?