Statement
Solution
Naive approach
The naive approach uses recursion to consider every possible path that the robot can take from the top-left corner of the grid to the bottom-right corner. The algorithm begins with the top-left corner and explores two branches: moving right and moving down. This process continues recursively, generating further branches for each valid move. Eventually, the recursion reaches the base cases:
If the robot reaches the bottom-right corner, a single path is counted.
If it goes out of bounds or reaches an edge, such a path is not counted.
The algorithm sums up the number of paths obtained through these recursive explorations and returns this number as the total number of unique paths.
Since this approach recalculates the overlapping subproblems, it becomes inefficient as the grid size grows, resulting in exponential time complexity. The robot takes a total of