PPractick

DSA interview question

Grid Unique Paths

Medium · Algorithms · Topics: dynamic programming, combinatorics

The problem

You're building the same warehouse robot navigation simulator as before, but this time there are no obstacles — the warehouse floor is completely clear. A robot starts at the top-left corner of an m x n grid and needs to reach the bottom-right corner, moving only right or down at each step. Your task: compute the total number of distinct paths the robot can take from start to destination.

Example: a 3x7 grid → there are 28 unique ways to get from top-left to bottom-right moving only right or down.

Function signature

int uniquePaths(int m, int n);

Test cases

Input mInput nOutputExplanation
3728Standard grid, 6 rights + 2 downs arranged in any order
3233 paths: RD-D, D-RD, DD-R style arrangements
111Start = end, exactly one trivial "path" (do nothing)
151Single row, only one path — go straight right
511Single column, only one path — go straight down
7328Same as (3,7) — problem is symmetric in m and n

(Confirm: m, n >= 1; grid has no obstacles in this version.)

How interviewers phrase it

Clarifying questions to ask

  1. Are the only allowed moves right and down — no diagonal, no up/left?
  2. Are m and n guaranteed to be at least 1? What's the expected upper bound on m and n — does it hint at whether a DP or a closed-form combinatorial solution is expected?
  3. Should the result fit in a standard int, or could it be large enough to need long long / modulo arithmetic for very large grids?
  4. Is this a warm-up for a follow-up involving obstacles, or is a pure combinatorial answer acceptable and preferred?

Follow-ups to expect

  1. "Can you solve this without DP, using combinatorics?"
  2. "What if obstacles are introduced?"
  3. "Can you compute the combinatorial answer without overflow for large m, n?"
  4. "Can you reduce DP space to O(min(m,n))?"
  5. "What if diagonal moves are also allowed?"
  6. "Can you do this recursively with memoization instead of iterative DP or combinatorics?"

Practise questions like this with a real engineer

On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.

Book a free mock interview

Related questions

All 474 dsa interview questions

DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in