FastPrepGrid Pathfinding with Obstacles (DFS)
Problems/Grid Pathfinding with Obstacles (DFS)

Grid Pathfinding with Obstacles (DFS)

Roblox logoRoblox● MediumFULLTIMENEW GRADPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Two Roblox interview reports written by their authors back this version. Our version is about 55% the same as the reported question. The reports describe reaching cells on a grid, obstacles, movement set by the current cell, and a follow-up on the shortest path. We chose the exact walk and jump distances, the directions, and what happens on landing.

You are given a 2D grid of characters representing a board. Each cell is one of:

  • 'W' — a walk cell. From here the player moves 1 step to any of the four orthogonal neighbours.
  • 'J' — a jump cell. From here the player moves exactly 2 cells in any of the four orthogonal directions (skipping over the cell in between).
  • '#' — an obstacle. The player cannot stand on this cell.

The move type at each step is determined by the cell the player is currently on, not where they are moving to. A move is valid only if the landing cell is inside the grid and is not an obstacle. When jumping, the player may fly over an obstacle in the cell between — only the landing square must be non-obstacle.

You are also given a start and a target coordinate, both guaranteed to be inside the grid and on a non-obstacle cell.

Return true if the player can reach target from start under these rules, and false otherwise. The prompt specifically asks for a DFS: treat each non-obstacle cell as a node whose outgoing edges depend on whether it is 'W' (four 1-step neighbours) or 'J' (four 2-step neighbours), and recurse with a visited set to avoid cycles.

Follow-up. Return the minimum number of moves to reach target (or -1 if unreachable). Because every walk and every jump counts as one unit-weight move, switch to BFS: explore cells in layers of increasing distance, and the first time the target is reached the recorded distance is minimal.

Alternate variant. A simpler reported form uses a grid of '.' (empty, walkable) and '#' (obstacle) cells with plain 1-step moves in the four orthogonal directions, and asks only whether end is reachable from start via DFS. The Walk/Jump version above generalizes it by making the step size cell-dependent.

Function

canReach(grid: String[], start: int[], target: int[]) → boolean

Examples

Example 1

grid = ["WWW", "W#W", "WWW"]start = [0, 0]target = [2, 2]return = true
grid
0120WWW1W#W2WWW

Every non-obstacle cell is a walk cell, so the player moves one step at a time. An L-shaped path around the obstacle at (1,1) reaches the target, for example (0,0) -> (1,0) -> (2,0) -> (2,1) -> (2,2).

Example 2

grid = ["JWW", "###", "WWW"]start = [0, 0]target = [2, 0]return = true
grid
0120JWW1###2WWW

Cell (0,0) is a jump cell, so the player jumps 2 cells down, flying over the obstacle at (1,0) and landing on the non-obstacle cell (2,0), which is the target. Only the landing square must be clear.

Example 3

grid = ["WWWW", "####", "WWWW"]start = [0, 0]target = [2, 3]return = false
grid
01230WWWW1####2WWWW

Row 1 is a solid wall of obstacles. Walk cells only step 1, so the player can never cross from the top row to the bottom row, and the target is unreachable.

Constraints

  • 1 <= grid.length, grid[i].length <= 100
  • Each cell is 'W', 'J', or '#' (or, in the alternate variant, '.' or '#').
  • start and target are length-2 [row, col] pairs inside the grid, each on a non-obstacle cell.
  • 0 <= start[0], target[0] < grid.length and 0 <= start[1], target[1] < grid[0].length.

More Roblox Phone Screen questions

  • Most Frequent Call Path From Function Trace LogsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Design Search Autocomplete SystemPHONE SCREEN · ONSITE INTERVIEW · 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

  • Number of IslandsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Number of Islands with Diagonal ConnectivityGoogle · ONSITE INTERVIEWGoogle interview questions
  • Island Count and Maximum AreaOracle · ONSITE INTERVIEWOracle interview questions
  • Count Connected IslandsUber · PHONE SCREENUber interview questions
  • Number of IslandsSpaceX · PHONE SCREENSpaceX interview questions
  • Mouse and Cheese ReachabilityMeta · ONSITE INTERVIEWMeta interview questions
  • Count Islands in a Binary GridApple · PHONE SCREENApple interview questions
  • Number of IslandsTripjack · ONSITE INTERVIEWTripjack interview questions
  • Pacific Atlantic Water FlowAnduril · PHONE SCREENAnduril interview questions
  • Number of IslandsTekion · ONSITE INTERVIEWTekion interview questions

Interview reports that mention this question

  • Roblox New Grad HackerRank OA: 18 Experiences (Part 5 of 7)

Roblox interview experiences

  • Roblox OA: What It Tests (2026)
  • Roblox New Grad Early OA Tasks: 10 Experiences (Part 7 of 7)
  • Roblox New Grad Engineer Rounds: 13 Experiences (Part 6 of 7)
  • Roblox New Grad CodeSignal Finals: 23 Experiences (Part 4 of 7)
  • Roblox New Grad Games and BQ: 25 Experiences (Part 3 of 7)
All Roblox interview questionsSee Roblox hiring insights
Saved
class Solution {
    public boolean canReach(String[] grid, int[] start, int[] target) {
      // write your code here
    }
}
Checking account…