Matrix Path Existence
Updated
Problem statement
Given a rectangular binary matrix grid, determine whether a path exists from the top-left cell to the bottom-right cell.
- A cell containing
1is passable. - A cell containing
0is blocked. - You may move one cell at a time up, down, left, or right.
Return true when such a path exists and false otherwise.
Function
pathExists(grid: int[][]) → booleanExamples
Example 1
grid = [[1,1,0],[0,1,1],[0,0,1]]return = trueA path follows the passable cells from the top-left cell through the center to the bottom-right cell.
Example 2
grid = [[1,0],[0,1]]return = falseDiagonal movement is not allowed, so the two passable cells are disconnected.
Example 3
grid = [[1]]return = trueThe single cell is both the start and the destination.
Example 4
grid = [[0,1],[1,1]]return = falseThe starting cell is blocked.
Constraints
1 <= grid.length <= 200.1 <= grid[i].length <= 200.- Every row has the same length.
grid[i][j]is0or1.
More Wells Fargo Online Assessment questions
- Server Upgrade PlanningOA · Seen Nov 2026
- Student and Course EnrollmentOA · Seen Nov 2026
- Bond Interest Summary Above 3%OA · Seen Oct 2026
- Count Phrases Formed by Anagram ReplacementOA · Seen Oct 2026
- Event Statistics AggregatorOA · Seen Sep 2026
- Ordered Deployment Configuration ValidatorOA · Seen Sep 2026
- Longest Subsequence That Is a SubstringOA · Seen Jul 2026
- Overloaded Game Account InventoriesOA · Seen Jul 2026
- Count Server ReplacementsOA · PHONE SCREEN · Seen Feb 2026
- Minimum Remaining LengthOA · PHONE SCREEN · Seen Feb 2026
Similar questions at other companies
- Minimize CommuteDatabricks · OA · PHONE SCREENDatabricks interview questions
- Shortest Atom Action PathOpenAI · OAOpenAI interview questions
- Minimum Cleaning Robot RunsHSBC · OAHSBC interview questions
- Count Islands with DFS and BFSVisa · OAVisa interview questions
- Number of IslandsGoldman Sachs · OA · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
- Count One Groups by SizeAgoda · OAAgoda interview questions
- Ascend Vertical Wall (For off-campus 2025 batch hiring :)Uber · OAUber interview questions
- Grid ExplorationIMC Trading · OAIMC Trading interview questions
- Maximum Damage PatchGecko Robotics · OA · PHONE SCREEN
- Nearest Different Maze Exit for a SnakeIntuit · OAIntuit interview questions