Robot Shortest Walkable Path
Updated
Problem statement
You control a robot in a rectangular binary grid. A cell containing 1 is walkable and a cell containing 0 is an obstacle. In one move, the robot may go up, down, left or right to a neighboring walkable cell inside the grid. Obstacles cannot be crossed or removed.
Return the minimum number of moves from start to target. For this exercise, assume each coordinate is a zero-based [row,column] pair. Return -1 when either endpoint is blocked or no path exists; return 0 when both coordinates name the same walkable cell. Keep all inputs unchanged.
Function
shortestPath(grid: int[][], start: int[], target: int[]) → intExamples
Example 1
grid = [[1,0,1],[1,1,1]]start = [0,0]target = [0,2]return = 4Walk down, right, right and up; the obstacle prevents a shorter route.
Example 2
grid = [[1,0],[0,1]]start = [0,0]target = [1,1]return = -1The two walkable cells touch only diagonally.
Example 3
grid = [[1]]start = [0,0]target = [0,0]return = 0The robot is already at the walkable target.
Constraints
- The grid has
1..50rows and1..50columns. - Every cell is
0or1. startandtargeteach contain two in-bounds coordinates.
More Roblox Phone Screen questions
- Design Search Autocomplete SystemPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Most Frequent Call Path From Function Trace LogsPHONE SCREEN · Seen Nov 2026
- Candy Crush Grid Matching and GravityPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Implement a Rate LimiterPHONE SCREEN · Seen Oct 2026
- Rate Limit by Multiple Request FieldsPHONE SCREEN · Seen Oct 2026
- Topological Sort with Secondary OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Time-Aware Search AutocompletePHONE SCREEN · Seen Oct 2026
- Most Frequent Call Stack Per ThreadPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Rate Limiter Sliding Window With Per-Entity LimitsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Closest Binary Search Tree Value — Base PracticePHONE SCREEN · Seen Jun 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