Obstacle-Aware Return to Origin
Reported by candidates from Waymo's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The data structure carries this whole Waymo problem, and it's a hash set. The OA reported in September 2026 gives you a robot, a string of moves, and a list of blocked cells. You return true only if the robot dodges every obstacle and ends at (0,0). It looks like a warm-up, and it is, but one wrong container choice turns it into a timeout on 10^5 inputs. If you blank on the setup during the live assessment, StealthCoder runs invisibly as a safety net and hands you the approach. Here's the pattern and the trap before you sit down.
The problem
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.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Dump every obstacle into a hash set first. Then walk the moves once, updating x and y, and check the new coordinate against the set after each step. If it's in the set, return false immediately. After the loop, return true only if x and y are both 0. That's O(n + m) time and O(m) space. The pitfall is scanning the obstacles array on every move, which is O(n*m) and dies at 10^5 each. The second pitfall is encoding the key. Use a string like x + "," + y, or pack the pair into one long with an offset, since coordinates go negative. Also check obstacles during the walk, not only at the end. Example 2 fails exactly because of that. Empty moves returns true since the origin is never blocked. If the live OA freezes you on the key encoding, StealthCoder can supply a clean version while you keep your hands moving.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Obstacle-Aware Return to Origin cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Waymo's OA.
Waymo reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Obstacle-Aware Return to Origin FAQ
What's the trick in Waymo's Obstacle-Aware Return to Origin?+
Put the obstacles in a hash set so each move costs O(1) to check. Simulate the path once, test every visited cell against the set, and confirm you end at (0,0). Everything else is bookkeeping around that single idea.
How hard is this problem really?+
It's easy. The logic is a straight simulation. The only way to fail is performance, by scanning the obstacle list on every step, or by a bad key for negative coordinates. Get the set right and it's a ten-minute problem.
How do I store coordinates in the set?+
Use a string key like x + "," + y, or a tuple in Python. In typed languages, pack x and y into one long with an offset so negatives work. Don't hash raw arrays by reference, since two equal arrays won't match.
Do I need to check obstacles after every move or only the end?+
After every move. Example 2 shows why: the robot steps into the blocked cell mid-path, so the answer is false even if it later returns home. Checking only the final position misses that case.
What edge cases should I test before submitting?+
Test empty moves, which should return true. Test an empty obstacle list with a path that doesn't return home, like Example 3. Test an obstacle on the first step, and a path with negative coordinates. Also run a 10^5 length input mentally for complexity.