FastPrepUnique Grid Paths

Unique Grid Paths

Morgan Stanley logoMorgan Stanley● MediumFULLTIMEPHONE SCREEN

Problem statement

An m by n grid has no blocked cells. Start at the top-left cell and reach the bottom-right cell.

Each move goes one cell right or one cell down. Return the number of different paths. Two paths differ if their sequences of visited cells differ.

When the start and destination are the same cell, the path with no moves counts as one path. Return the exact count as a long.

Function

uniquePaths(m: int, n: int) → long

Examples

Example 1

m = 3n = 3return = 6

Each path has two right moves and two down moves. Choosing the two right-move positions among four positions gives 6 paths.

Example 2

m = 1n = 4return = 1

The only path makes three right moves.

Constraints

  • 1 <= m, n <= 20.

More Morgan Stanley problems

See Morgan Stanley hiring insights
Saved
public long uniquePaths(int m, int n) {
    // write your code here
}
m3
n3
expected6
Checking account…