The Unique Paths interview question is a classic grid-based challenge. You have a robot placed at the top-left corner of an grid. The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid. You need to calculate the total number of unique paths the robot can take.
This is one of the most famous Dynamic Programming and Combinatorics coding problems, asked by almost every major tech company including Amazon, LinkedIn, and Google. It tests whether a candidate can break a large problem into smaller sub-problems. It also allows for multiple solutions, ranging from recursion (slow) to DP (efficient) to pure math (fastest), giving interviewers a clear look at a candidate's depth of knowledge.
There are two main Math, Combinatorics, Dynamic Programming interview patterns.
(i, j) is the sum of the ways to reach the cell above it (i-1, j) and the cell to its left (i, j-1). By filling a 2D table (or even a 1D array to save space), you can find the answer in time.For a grid:
[1, 1] (only one way to go right)[1, 2] (1 from above + 1 from left)[1, 3] (1 from above + 2 from left)The most common mistake is using simple recursion without memoization, which leads to a time limit exceeded (TLE) error because the same sub-problems are calculated millions of times. Another mistake is integer overflow when calculating the combinations formula with large and .
Always start with the Dynamic Programming explanation, as it shows you understand the recursive nature of the problem. If the interviewer asks for a more optimal solution, then mention the Combinatorics approach. Understanding both the "how" (DP) and the "why" (Math) is the sign of a top-tier candidate.