FastPrepShortest Maze Path With One Block Removal
Problems/Shortest Maze Path With One Block Removal

Shortest Maze Path With One Block Removal

Google logoGoogle● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives a maze of free and blocked cells, a top-left start, a bottom-right destination, a BFS shortest path, and a follow-up where one block may become free, using visited[row][col][used] state. We chose how cells are encoded, four-direction movement, the value returned for no path, concrete examples, and the input limits. Our version is about 94% the same as the reported question.

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[][]) → int

Examples

Example 1

maze = [[0,1],[0,0]]return = 2
maze
01001100

Move down and then right without using the removal.

Example 2

maze = [[0,1,0],[1,1,0],[0,0,0]]return = 4
maze
012001011102000

Remove 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 = -1
maze
012001111112110

Every 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 0 or 1.
  • 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

Interview reports that mention this question

  • Google New Grad Four-Round Coding Onsite: 1 Experience

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int shortestPathWithOneRemoval(int[][] maze) {
        // write your code here
    }
}
Checking account…