Explore an Unknown Grid and Find a Path
Updated
Problem statement
A robot starts in an unexplored rectangular area. In this version, hiddenMap is the map the robot cannot see: . is an open cell and # is a wall. The robot starts at start = [row, column], knows the target coordinate, and may inspect the four orthogonal neighbors of any cell it has already explored. It may also relocate to any previously explored open cell before continuing exploration.
Return a shortest open-cell path from start to target, including both endpoints. If several shortest paths exist, choose the lexicographically smallest coordinate sequence when coordinates are compared as [row, column]. Return an empty array when the target cannot be reached.
The hidden map tells the robot what it finds at each cell it inspects.
Function
findExploredPath(hiddenMap: String[], start: int[], target: int[]) → int[][]Examples
Example 1
hiddenMap = ["...",".#.","..."]start = [0,0]target = [2,2]return = [[0,0],[0,1],[0,2],[1,2],[2,2]]Two shortest paths have four moves. The path beginning with [0,1] is lexicographically smaller than the one beginning with [1,0].
Example 2
hiddenMap = [".#.","###",".#."]start = [0,0]target = [2,2]return = []Walls separate the target from the start.
Constraints
1 <= hiddenMap.length, hiddenMap[i].length <= 500.- All rows have equal length and contain only
.and#. startandtargetidentify open cells.- The robot explores only up, down, left, and right neighbors.
More LinkedIn Onsite Interview questions
- Allocate Mailboxes with Squared DistanceONSITE INTERVIEW · Seen Nov 2026
- Find Leaves of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
- Max Points on a LineONSITE INTERVIEW · Seen Nov 2026
- Fire Station Response BillONSITE INTERVIEW · Seen Nov 2026
- Roll a Weighted DieONSITE INTERVIEW · Seen Oct 2026
- Longest Binary Subarray With at Most K OnesONSITE INTERVIEW · Seen Oct 2026
- Kth Closest Element in a BSTONSITE INTERVIEW · Seen Oct 2026
- Longest Binary Window with at Most K OnesONSITE INTERVIEW · Seen Oct 2026
- LRU Cache OperationsONSITE INTERVIEW · Seen Oct 2026
- Lexicographically Smallest Course OrderONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Xiangqi Horse ReachabilityeBay · PHONE SCREENeBay interview questions
- Number of IslandsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Nearest Charging Station on a GridSpotify · ONSITE INTERVIEW
- Number of Islands with Diagonal ConnectivityGoogle · ONSITE INTERVIEWGoogle interview questions
- Island Count and Maximum AreaOracle · ONSITE INTERVIEWOracle interview questions
- Shortest Increasing Path to a TargetUber · ONSITE INTERVIEWUber interview questions
- Mouse and Cheese ReachabilityMeta · ONSITE INTERVIEWMeta interview questions
- Number of IslandsTripjack · ONSITE INTERVIEWTripjack interview questions
- Number of IslandsTekion · ONSITE INTERVIEWTekion interview questions
- Grid Pathfinding with Obstacles (DFS)Roblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions