Unique Paths Through a Grid
Updated
Problem statement
Given the number of rows m and columns n in a rectangular grid, count the distinct paths from the top-left cell to the bottom-right cell.
For this exercise, assume every cell is open and each move goes exactly one cell right or one cell down. Paths are distinct when their sequences of visited cells differ. Return the exact count as a 64-bit integer.
Function
uniquePaths(m: int, n: int) → longExamples
Example 1
m = 3n = 4return = 10Each path contains two down moves and three right moves. Choosing the two down positions among five moves gives 10 paths.
Example 2
m = 1n = 5return = 1There is only one row, so the only path moves right four times.
Constraints
- For this exercise, assume
1 <= m, n <= 20. - No blocked cells or other movement directions are part of this exercise.
- The result fits in a signed 64-bit integer.
More PeopleStrong interview questions
- Reverse Linked-List Nodes in Groups of KOA · PHONE SCREEN · Seen Mar 2026
- Aggressive CowsOA · Seen Oct 2021
- Shortest Path in an Unweighted GraphOA · Seen Oct 2021
- Total Set Bits from 1 to NOA · Seen Oct 2021
- Swap Two Array ElementsOA · Seen Sep 2021
- Minimum Travel Time with Flashing Traffic LightsOA · Seen Aug 2021
- Permutation in a StringOA · Seen Aug 2021
- Rat in a Maze: All Simple PathsOA · Seen Aug 2021
- Add Two Binary StringsONSITE INTERVIEW · Seen Mar 2026
- Four SumONSITE INTERVIEW · Seen Mar 2026
Similar questions at other companies
- Frog Paths Without Long RunsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Count Lucky TicketsThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
- Maximum Score with Prime JumpsMicrosoft · OAMicrosoft interview questions
- Jump Game with Prime-Step RuleUber · OAUber interview questions
- Count Shipment SchedulesMorgan Stanley · OAMorgan Stanley interview questions
- Get Minimum OperationsJP Morgan Chase · OAJP Morgan Chase interview questions
- Jump Game with Prime-3 StepsAgoda · OAAgoda interview questions
- Find Encrypted NumberAmazon · OA
- Prime StringSnowflake · OASnowflake interview questions
- Valid PasswordsMathWorks · OAMathWorks interview questions