Min Obstacle to Remove
Reported by candidates from Uber's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
You've got an Uber OA in the queue and the problem is Min Obstacle to Remove. This is a shortest-path problem disguised as a grid puzzle. You're looking for the minimum number of obstacles to clear to get from one corner to another, usually in a 2D matrix. The trap is assuming you need Dijkstra or BFS without considering what you're actually optimizing for. Since you're counting obstacles, not distance, the approach shifts. StealthCoder will have the pattern locked in if you blank on the transition from standard pathfinding.
Pattern and pitfall
This problem asks you to find the minimum count of obstacles that block a path in a grid. The key insight is that you're not finding shortest distance, you're finding the path that removes the fewest walls. BFS works here, but you need to treat it as a 0-1 weighted graph: moving through empty space costs 0, moving through an obstacle costs 1. Some candidates jump to Dijkstra immediately, which is overkill. Others miss that you can use a deque-based BFS (0-1 BFS pattern) to process 0-cost edges first and 1-cost edges last, avoiding the overhead of a priority queue. The pitfall is overthinking the weight system. StealthCoder catches this by surfacing the 0-1 BFS pattern before you lock into a slower solution.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Min Obstacle to Remove cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Uber's OA.
Uber reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Min Obstacle to Remove FAQ
Is this really just BFS with a twist?+
Mostly yes. Standard BFS finds shortest path in unweighted graphs. Here you have two costs: 0 (empty cell) and 1 (obstacle). Use a deque, not a queue. Push 0-cost moves to the front, 1-cost to the back. This is 0-1 BFS and it's faster than Dijkstra for this constraint.
What's the gotcha with obstacle counts?+
Candidates often try to count obstacles along a path instead of finding the path with minimum obstacles. You're not summing obstacle values. You're finding the shortest path where edge weights are 0 or 1 based on cell type. The answer is the minimum weight to reach the goal.
Do I need Dijkstra for this?+
No. Dijkstra works but it's slower (O(n log n) with a heap vs O(n) with 0-1 BFS and a deque). Since weights are only 0 and 1, the deque approach is cleaner and faster. Uber's OA timing favors the efficient pattern.
How do I set up the deque correctly?+
Start at the source. For each neighbor, if the cost is 0, add it to the front of the deque. If the cost is 1, add to the back. This ensures you process all 0-cost paths before 1-cost, guaranteeing optimality without sorting.
What if the grid allows diagonal movement?+
Check the problem statement carefully. If diagonals are allowed, you have 8 neighbors instead of 4. The 0-1 BFS logic stays the same. The reported problem doesn't specify, so assume 4-directional (up, down, left, right) unless told otherwise.