FastPrepEnumerate Grid Paths

Enumerate Grid Paths

Motive logoMotive● MediumFULLTIMEONSITE INTERVIEW
Learn

Problem statement

Starting at the top-left cell of a rows-by-cols grid, move only down (D) or right (R) until the bottom-right cell. Return every path as a move string in lexicographic order.

Function

enumerateGridPaths(rows: int, cols: int) → String[]

Examples

Example 1

rows = 2cols = 3return = ["DRR","RDR","RRD"]

Example 2

rows = 1cols = 1return = [""]

Constraints

  • 1 <= rows, cols <= 8.

More Motive problems

See Motive hiring insights
public String[] enumerateGridPaths(int rows, int cols) {
  // write your code here
}
rows2
cols3
expected["DRR", "RDR", "RRD"]
Checking account…