MEDIUMasked at 2 companies

Nearest Exit from Entrance in Maze

A medium-tier problem at 48% community acceptance, tagged with Array, Breadth-First Search, Matrix. Reported in interviews at eBay and 1 others.

Founder's read

You're in a maze, you know your starting point, and you need the shortest path to any exit. Sounds simple until you code it and realize you're either re-visiting cells, not tracking distance properly, or iterating through the matrix wrong. eBay and Samsung ask this one. The acceptance rate sits below 48%, meaning most candidates either solve it slowly or miss edge cases around what counts as an exit or how to measure steps. If this problem hits your live OA and you blank on the BFS setup, StealthCoder runs invisibly during screen share and surfaces a working solution in seconds.

Companies asking
2
Difficulty
MEDIUM
Acceptance
48%

Companies that ask "Nearest Exit from Entrance in Maze"

If this hits your live OA

Nearest Exit from Entrance in Maze 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 a senior engineer who knows the OA is theater. This is the script.

Get StealthCoder
What this means

This is a textbook breadth-first search problem dressed up as a maze. The trick most candidates miss: an exit isn't just any cell; it's on the boundary of the matrix. So you can't naively mark visited cells and then search inward. You need to start a multi-source BFS from all valid cells, track distance accurately, and handle the boundary condition correctly. The obvious mistake is treating it like a single-source shortest-path problem, which kills your code on test cases where the nearest exit isn't reachable or where you've miscounted steps. Array and Matrix operations are straightforward, but the logic falls apart if you misunderstand what the problem considers an entrance versus an exit. When you're stuck during the assessment, StealthCoder reads the problem on screen and delivers the correct BFS approach without any proctor visibility.

Pattern tags

The honest play

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

Nearest Exit from Entrance in Maze recycles across companies for a reason. It's medium-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 a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Nearest Exit from Entrance in Maze interview FAQ

Is this problem really Medium, or is it harder?+

The acceptance rate is 47.6%, which is low for Medium. The difficulty label is accurate, but the problem trips up candidates who rush the boundary logic or implement BFS sloppily. The core concept is straightforward; execution details matter.

Do I need dynamic programming or just BFS?+

Just BFS. This is a shortest-path problem in an unweighted grid. BFS guarantees the shortest distance from any starting point. Dynamic programming is overkill and signals you've misunderstood the problem.

What's the trick to identifying exits correctly?+

An exit is a cell on the boundary of the matrix that you can actually reach from the entrance. Don't confuse boundary cells with open cells. You must check both conditions: is it on an edge, and is it passable (not a wall).

Do eBay and Samsung ask this the same way?+

Both companies reportedly ask it, but interview problems sometimes vary slightly in constraints or input format. The core algorithm stays the same: BFS from entrance(s) to find nearest boundary cell. Clarify input format early in your actual interview.

How do I avoid re-visiting cells in BFS?+

Mark cells as visited the moment you add them to the queue, not when you pop them. A separate boolean matrix or in-place mutation of the original grid works. If you mark visited after popping, you risk adding the same cell multiple times and inflating your step count.

Want the actual problem statement? View "Nearest Exit from Entrance in Maze" 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.