FastPrepShortest Grid Path with Obstacle Elimination
Problems/Shortest Grid Path with Obstacle Elimination

Shortest Grid Path with Obstacle Elimination

Google logoGoogle● HardINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives a binary grid, movement in four directions, top-left and bottom-right endpoints, a budget for removing obstacles, the goal of the shortest length, the result for unreachable, the BFS state, a follow-up on pruning states, and a talk about production readiness. We added the rule for valid endpoints and input limits that work anywhere. Our version is about 97% the same as the reported question.

You are given an m x n binary grid. A value of 0 is an open cell, and a value of 1 is an obstacle.

Start at the top-left cell (0, 0). In one step, you may move one cell up, down, left, or right while remaining inside the grid. You may eliminate at most k obstacles by entering their cells.

Return the minimum number of steps needed to reach the bottom-right cell (m - 1, n - 1). Return -1 when no valid path exists.

Function

shortestPathWithObstacleEliminations(grid: int[][], k: int) → int

Examples

Example 1

grid = [[0,0,0],[1,1,0],[0,0,0],[0,1,1],[0,0,0]]k = 1return = 6
grid
01200001110200030114000

A shortest route uses six steps and eliminates one obstacle.

Example 2

grid = [[0,1,1],[1,1,1],[1,0,0]]k = 1return = -1
grid
012001111112100

Every route to the destination enters more than one obstacle, so the elimination budget is insufficient.

Example 3

grid = [[0]]k = 0return = 0
grid
000

The start is already the destination, so no step is needed.

Constraints

  • 1 <= m, n <= 40
  • grid[i][j] is 0 or 1.
  • grid[0][0] = grid[m - 1][n - 1] = 0
  • 0 <= k <= m * n

More Google Onsite Interview questions

  • 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
  • Route Pattern MatcherPHONE SCREEN · ONSITE 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

  • Shortest Grid Path with Obstacle EliminationsAmazon · ONSITE INTERVIEW
  • Shortest Path in a Grid with Obstacles EliminationBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Fire Station Response BillLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • Shortest Increasing Path to a TargetUber · ONSITE INTERVIEWUber interview questions
  • Find and Reconstruct a Binary-Matrix PathMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Safest Shortest Path Through a GridSnowflake · OASnowflake interview questions
  • Competitive ForagingAkuna Capital · OAAkuna Capital interview questions
  • Shortest Distance from All BuildingsWaymo · PHONE SCREENWaymo interview questions
  • Shortest Path in a Grid with Obstacles EliminationMercor · PHONE SCREENMercor interview questions
  • Drone Delivery with Battery Swap StationsCisco · OACisco interview questions

Interview reports that mention this question

  • Google SWE III ML Loops in India: 10 Experiences (Part 2 of 3)
  • Google Intern Grid and Tree Rounds: 7 Experiences (Part 2 of 8)

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
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int shortestPathWithObstacleEliminations(int[][] grid, int k) {
        // Write your code here.
    }
}
Checking account…