HARDasked at 7 companies

Shortest Path in a Grid with Obstacles Elimination

A hard-tier problem at 46% community acceptance, tagged with Array, Breadth-First Search, Matrix. Reported in interviews at AppFolio and 6 others.

Founder's read

You're in a grid, there are walls, and you can destroy a limited number of them. Find the shortest path from top-left to bottom-right. This is a hard-rated grid problem that shows up at AppFolio, Pinterest, Nuro, Snap, IMC, Databricks, and TikTok. The acceptance rate is 45.6%, which means most candidates either miss the state-space trick or build the wrong BFS structure. You probably think standard shortest-path BFS will work. It won't. The catch is that your position alone isn't enough state, you also need to track how many obstacles you've eliminated so far. If you hit this problem live and your first BFS attempt fails, StealthCoder surfaces the correct state model instantly, invisible to the proctor.

Companies asking
7
Difficulty
HARD
Acceptance
46%

Companies that ask "Shortest Path in a Grid with Obstacles Elimination"

If this hits your live OA

Shortest Path in a Grid with Obstacles Elimination is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share.

Get StealthCoder
What this means

The core insight is that position (row, col) is not enough. You need (row, col, eliminations_used). Two paths to the same cell are different if one used fewer eliminations. Standard BFS collapses them into one visit and prunes the better path. You need a 3D visited array or a map keyed on (row, col, k) to track all reachable states. The BFS explores each state, tries all four directions, and when it hits a wall, it checks if you still have eliminations left. If yes, eliminate the obstacle and move into it, that's a new state. If no, you can't pass. The goal is any state (rows-1, cols-1, k) for 0 <= k <= obstacle_count. Common miss: building a 2D visited array instead of 3D, or not realizing that reaching the same cell with different elimination counts is actually different. When the obvious BFS approach doesn't work and you're running out of time, StealthCoder runs in the background and hands you the correct state representation and BFS loop.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Shortest Path in a Grid with Obstacles Elimination recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Shortest Path in a Grid with Obstacles Elimination interview FAQ

Is this really a hard problem or just a BFS variant?+

It's hard because the state space is non-obvious. Standard shortest-path BFS doesn't work. You must track three dimensions: row, column, and obstacles eliminated. Candidates who only track position fail. The problem teaches you that 'reachability' doesn't mean 'unique cell', it means unique (position, resource) pairs. That jump in thinking is what makes it hard-rated.

Do I need a 3D array or can I use a set or map?+

Both work. A 3D array of size (m, n, k+1) is fastest if k is small. A set of tuples (row, col, eliminations) or a map keyed on the same works fine and uses less memory if k is large. Most solutions use the 3D array. Pick what fits your language and confidence level.

When I hit an obstacle, do I have to eliminate it, or can I skip it?+

You can skip it if you have eliminations left. The BFS explores both choices: go around (if open) or eliminate and pass (if obstacles remain). You don't pre-decide. That's why the state tracks eliminations, it lets the algorithm decide the optimal path, not you.

Do companies like Snap and TikTok really ask this, or is it just category padding?+

Both appear in reported interview data for this problem. At that level, hard grid problems with a trick are common. This one combines BFS, state design, and obstacle handling, all useful signals. It's not common, but it's real.

What if I see this in the OA and blank on the state trick?+

That's exactly what StealthCoder handles. You describe the problem on screen, it reads the grid constraints, and outputs the 3D BFS structure and loop in seconds, all invisible to the proctor. You paste, submit, move on.

Want the actual problem statement? View "Shortest Path in a Grid with Obstacles Elimination" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.