Shortest Maze Path With One Block Removal
Updated
Problem statement
maze is a rectangular grid where 0 is free and 1 is blocked. Start at the top-left cell and reach the bottom-right cell by moving up, down, left, or right.
You may change at most one blocked cell into a free cell when entering it. Return the minimum number of moves needed, or -1 when the destination cannot be reached. The start and destination cells are free.
Function
shortestPathWithOneRemoval(maze: int[][]) → intExamples
Example 1
maze = [[0,1],[0,0]]return = 2Move down and then right without using the removal.
Example 2
maze = [[0,1,0],[1,1,0],[0,0,0]]return = 4Remove either blocked neighbor of the start, then continue to the destination in four moves.
Example 3
maze = [[0,1,1],[1,1,1],[1,1,0]]return = -1Every route needs more than one blocked cell to be removed.
Constraints
1 <= maze.length, maze[0].length <= 200.- Every row has the same length.
- Every cell is
0or1. maze[0][0] == maze[m - 1][n - 1] == 0.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Number of IslandsFleetx · ONSITE INTERVIEW
- Minimum Time to Spread Through a GridAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Number of IslandsIntuit · ONSITE INTERVIEWIntuit interview questions
- Rotting OrangesSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Shortest Bridge Between Two IslandsCompass International Holdings · ONSITE INTERVIEWCompass International Holdings interview questions
- Explore an Unknown Grid and Find a PathLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Minimum Time to Rot All OrangesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Nearest Charging Station on a GridSpotify · ONSITE INTERVIEW
- Island Count and Maximum AreaOracle · ONSITE INTERVIEWOracle interview questions
- Number of Closed IslandsSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions