Check Whether a Warehouse Robot Returns to Its Charging Dock
Last updated: November 29, 2026
Quick Overview
A warehouse robot starts at its dock at (0, 0) facing north and executes a command string of 'G' (move one cell forward), 'L' (turn left) and 'R' (turn right). Return whether it ends at the dock, and as a follow-up, whether repeating the command string forever keeps it within a bounded area.
Amazon
November 29, 20260
0
0 solved
A warehouse robot starts at its dock at (0, 0) facing north and executes a command string of 'G' (move one cell forward), 'L' (turn left) and 'R' (turn right). Return whether it ends at the dock, and as a follow-up, whether repeating the command string forever keeps it within a bounded area.
Amazon Robotics themes appear often in Online Assessment style problems. The first part is direction-vector bookkeeping; the follow-up checks whether you can reason about the robot's state after one pass instead of simulating forever.
What the Interviewer Expects
- Represent heading as an index into a direction array
- Update position and heading in one pass
- For the bounded follow-up, argue from position and heading after one pass
- Prove why four repetitions suffice
- Handle empty and invalid commands
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you return the farthest distance the robot ever gets from the dock?
- What if the grid has obstacles the robot skips over?
- How would you verify many robots do not collide on the same instructions?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Commands are a string over {G, L, R}, possibly empty. Part 1: return True if the final position is (0, 0). Part 2: return True if the robot stays within some finite circle when the string repeats inde...
High-Level Design
Keep dirs = [(0,1), (1,0), (0,-1), (-1,0)] for north, east, south, west and a heading index. 'R' is h = (h + 1) % 4, 'L' is h = (h + 3) % 4, 'G' adds dirs[h].
Bounded test: after one pass, if...