FastPrepObstacle-Aware Return to Origin
Problems/Obstacle-Aware Return to Origin

Obstacle-Aware Return to Origin

Waymo logoWaymo● EasyFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The phone-screen report directly specifies four-direction movement from (0,0), returning to (0,0), and avoiding obstacles. The Boolean validator matches those preserved requirements at about 96%.

A robot starts at (0,0). Commands U, D, L, and R move one grid cell. Return true only when the robot never enters any coordinate in obstacles and finishes back at (0,0). The origin is never blocked.

Function

returnsSafely(moves: String, obstacles: int[][]) → boolean

Examples

Example 1

moves = "URDL"obstacles = []return = true

The four moves form a safe loop.

Example 2

moves = "URDL"obstacles = [[-1,1]]return = false

The robot enters the blocked cell after U then R.

Example 3

moves = "UUDDR"obstacles = []return = false

The path is safe but finishes one column to the right of the origin.

Constraints

  • 0 <= moves.length <= 10^5 and every character is U, D, L, or R.
  • 0 <= obstacles.length <= 10^5; obstacle coordinates are unique and exclude the origin.

More Waymo problems

  • Fixed-Order Task Run Time With CooldownPHONE SCREEN · Seen Oct 2026
  • Reorderable Task Scheduler With CooldownPHONE SCREEN · Seen Oct 2026
  • Island Area and Water BoundaryPHONE SCREEN · Seen Sep 2026
All Waymo interview questionsSee Waymo hiring insights
Saved
class Solution {
    public boolean returnsSafely(String moves, int[][] obstacles) {
        // Write your solution here.
    }
}
Checking account…