FastPrepReachable Exits in an Obstacle Grid
Problems/Reachable Exits in an Obstacle Grid

Reachable Exits in an Obstacle Grid

WhatNot logoWhatNot● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Whatnot new grad technical phone screen. The interviewer used one square grid with obstacles and grew the task in steps: count the obstacles per row and per column, find a shortest path from a start cell, then find every exit you can reach.

The report does not say how the grid is written, what an exit is, or what the shortest path leads to. Here, 0 is open and 1 is an obstacle, moves go up, down, left or right, an exit is an open edge cell other than the start, and you return each reachable exit with its fewest moves. The first counting step is covered in the editorial but not tested.

Our version is about 70% the same as the reported question.

You are given an n x n grid grid where 0 is an open cell and 1 is an obstacle, and a starting cell start = [row, col]. Return every exit you can reach from start, together with the fewest moves needed to reach it.

In one move you go one cell up, down, left or right into an open cell. You cannot move onto an obstacle or leave the grid.

An exit is an open cell on the outer edge of the grid (row 0, row n - 1, column 0 or column n - 1). The start cell is never an exit, even when it is on the edge.

Return a list of [row, col, steps] entries, one for each reachable exit, where steps is the length of the shortest path from start to that exit. Sort the list by row, then by col. If no exit can be reached, return an empty list.

Function

reachableExits(grid: int[][], start: int[]) → int[][]

Examples

Example 1

grid = [[0,0,1,0,0],[0,1,0,0,1],[0,0,0,1,0],[1,1,0,1,0],[0,0,0,0,1]]start = [2,2]return = [[0,0,4],[0,1,5],[0,3,3],[0,4,4],[1,0,3],[2,0,2],[4,0,4],[4,1,3],[4,2,2],[4,3,3]]
grid
01234000100101001200010311010400001
→
return
0120004101520333044410352026404741384229433

Ten exits can be reached. [2,0] is two moves left of the start. [0,1] needs five moves because the obstacles at [0,2] and [1,1] force the path around through [0,0]. The open edge cells [2,4] and [3,4] are walled off, so they are not listed.

Example 2

grid = [[1,0,1],[1,0,1],[1,1,1]]start = [0,1]return = []
grid
012010111012111

The start [0,1] is on the edge, but it is not an exit. The only other open cell is [1,1], which is not on the edge, so no exit can be reached.

Example 3

grid = [[1,1,1,1],[1,0,0,1],[1,0,0,1],[1,1,1,1]]start = [1,1]return = []
grid
012301111110012100131111

Every edge cell is an obstacle, so there are no exits.

Constraints

  • n == grid.length == grid[i].length
  • 1 <= n <= 100
  • grid[i][j] is 0 or 1.
  • start.length == 2
  • 0 <= start[0], start[1] < n
  • grid[start[0]][start[1]] == 0

More WhatNot Phone Screen questions

  • Adjacent Pair and Run RemovalPHONE SCREEN · Seen Nov 2026
  • Merge Sorted Squares of Two ArraysPHONE SCREEN · Seen Nov 2026
  • User Journey PathsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Knight Dialer SequencesPHONE SCREEN · Seen Oct 2026
  • Palindrome with One DeletionPHONE SCREEN · Seen Oct 2026
  • Search a 2D MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Attraction Route Without Reusing TrailsPHONE SCREEN · Seen Sep 2026
  • Earliest Car for Each PassengerPHONE SCREEN · Seen Sep 2026
  • Minimum Stores for a Shopping ListPHONE SCREEN · Seen Sep 2026
  • User Journey Paths from a Log StreamPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • Minimum Time to Spread Through a GridAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Max Area of Island Without Changing the GridFlexport · PHONE SCREENFlexport interview questions
  • Process Minesweeper Game OperationsAmperity · PHONE SCREENAmperity interview questions
  • Count Islands in a Binary GridApple · PHONE SCREENApple interview questions
  • Find and Reconstruct a Binary-Matrix PathMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Pacific Atlantic Water FlowAnduril · PHONE SCREENAnduril interview questions
  • Fuel-Aware Grid ReachabilityBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • House Bounds in a Ragged GridRippling · OA · PHONE SCREENRippling interview questions
  • Nearest Reachable Grid CornerSplunk · PHONE SCREENSplunk interview questions
  • Rotting Orange PropagationIndeed · PHONE SCREENIndeed interview questions

Interview reports that mention this question

  • Whatnot interviews · October 2026

WhatNot interview experiences

  • Whatnot SWE New Grad Second Technical Interview: 8 Experiences
  • Whatnot Experienced SWE Phone Screen Questions: 2 Experiences
  • Whatnot SWE Interview Questions: 6 Experiences
All WhatNot interview questionsSee WhatNot hiring insights
Saved
class Solution {
    public int[][] reachableExits(int[][] grid, int[] start) {
        
    }
}
Checking account…