FastPrepNearest Reachable Grid Corner
Problems/Nearest Reachable Grid Corner

Nearest Reachable Grid Corner

Splunk logoSplunk● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Splunk phone screen. The report asks for the nearest other passable corner you can reach by moving in four directions, and uses -1 when there is none. We chose alphabetical order to break ties, how the -1 is written, the limits and the function signature. Our version is about 94% the same as the reported question.

You are given a non-empty rectangular grid where 0 is passable and + is impassable. The passable starting cell (startRow, startCol) is one of the grid's geometric corners.

Moving one step up, down, left, or right through passable cells costs one. Find a different passable geometric corner reachable with minimum path distance. If several destinations have the same minimum distance, return the lexicographically smallest coordinate: smallest row, then smallest column.

Return the destination as [row, column], or [-1] if no different corner is reachable. Repeated coordinates in a one-row or one-column grid represent one geometric corner.

Function

nearestReachableCorner(grid: String[], startRow: int, startCol: int) → int[]

Examples

Example 1

grid = ["000","+0+","000"]startRow = 0startCol = 0return = [0,2]
grid
01200001+0+2000

The top-right corner is reachable in two steps, while the bottom-left and bottom-right corners require longer paths.

Example 2

grid = ["0+","++"]startRow = 0startCol = 0return = [-1]
grid
0100+1++

Every other geometric corner is impassable, so no destination is reachable.

Constraints

  • 1 <= grid.length.
  • 1 <= grid[i].length.
  • Every row has the same length and the grid contains at most 4,096 cells.
  • Every cell is 0 or +.
  • (startRow, startCol) is a geometric corner and is passable.

More Splunk Phone Screen questions

  • Completely Passable Grid LinesPHONE SCREEN · Seen Aug 2025
  • One-Roll Teleporter LandingsPHONE SCREEN · Seen Aug 2025
  • Repeated-Roll Teleporter ReachabilityPHONE SCREEN · Seen Aug 2025

Similar questions at other companies

  • Matrix EscapeByteDance · PHONE SCREENByteDance interview questions
  • Minimum Time to Spread Through a GridAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Max Area of Island Without Changing the GridFlexport · PHONE SCREENFlexport interview questions
  • Reachable Exits in an Obstacle GridWhatNot · PHONE SCREENWhatNot 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
All Splunk interview questionsSee Splunk hiring insights
Saved
class Solution {
    public int[] nearestReachableCorner(String[] grid, int startRow, int startCol) {
        // Return [row, column], or [-1].
    }
}
Checking account…