Enumerate Right-and-Down Matrix Paths
Updated
Problem statement
Given a non-empty rectangular binary matrix grid, return every path from the top-left cell to the bottom-right cell, sorted in lexicographic order. A cell with 1 is valid, and a cell with 0 is blocked.
Each move goes exactly one cell Down or one cell Right, and every cell the path visits must contain 1. Write a path as a string of its moves, using 'D' for Down and 'R' for Right. Lexicographic order sorts strings like a dictionary: compare them character by character, and at the first difference 'D' comes before 'R'.
If no path exists, including when the top-left or bottom-right cell is blocked, return an empty list. A valid 1-by-1 matrix has one path: the empty string.
Function
enumeratePaths(grid: int[][]) → List<String>Examples
Example 1
grid = [[1,1,1],[1,1,1]]return = ["DRR","RDR","RRD"]Every cell is valid, so all three paths work. With 'D' before 'R', they sort as "DRR", "RDR", then "RRD".
Example 2
grid = [[1,0],[1,1]]return = ["DR"]The cell to the right of the start is blocked, so the only path goes Down, then Right.
Example 3
grid = [[1]]return = [""]The start is already the destination, so the only path has no moves and is the empty string.
Example 4
grid = [[1,0],[0,1]]return = []Both first moves lead into blocked cells, so no path reaches the destination and the list is empty.
Constraints
1 <= grid.length <= 100and1 <= grid[i].length <= 100.- Every row has the same length.
- Every cell is either
0or1. - The total number of valid paths is at most
10000.
More Bloomberg LP Phone Screen questions
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Word Path Moving Only Right or DownIndeed · PHONE SCREENIndeed interview questions
- Word Path Moving Only Right or DownWayfair · PHONE SCREENWayfair interview questions
- Enumerate Right-and-Down Matrix PathsOracle · ONSITE INTERVIEWOracle interview questions
- Find a Word Path Moving Right or DownIntuit · OAIntuit interview questions
- Count Eight-Neighbor Unlock PatternsGoogle · ONSITE INTERVIEWGoogle interview questions
- Empty ShelfSquarepoint Capital · OASquarepoint Capital interview questions
- Count Complete Tic-Tac-Toe GamesDecagon · PHONE SCREEN · ONSITE INTERVIEWDecagon interview questions
- Unique Grid PathsMorgan Stanley · PHONE SCREENMorgan Stanley interview questions
- Count Starts Reaching a Grid MaximumDuolingo · PHONE SCREENDuolingo interview questions
- Find Robots by Blocker DistancesUber · PHONE SCREENUber interview questions
Bloomberg LP interview experiences
- Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
- Bloomberg SWE Intern Interview Questions: 68 Questions
- Bloomberg Interview Questions, Level Not Reported: 65 Questions
- Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
- Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
- Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)