Decide Whether a Looping Drone Flight Plan Stays Within Bounds
Last updated: November 29, 2026
Quick Overview
A survey drone starts at (0, 0) facing north and repeats a command string of G (go one unit), L (turn left), and R (turn right) forever. Return true if there is a circle it never leaves, meaning its path stays bounded.
0
0
0 solved
A survey drone starts at (0, 0) facing north and repeats a command string of G (go one unit), L (turn left), and R (turn right) forever. Return true if there is a circle it never leaves, meaning its path stays bounded.
A Google phone screen question that looks like it needs infinite simulation but reduces to one pass plus a short argument. The interviewer is grading the proof: after one pass, either the drone is back at the origin or it is not facing north.
What the Interviewer Expects
- Simulate exactly one pass of the instructions
- State the criterion: back at origin or heading changed
- Prove why a changed heading returns to origin within four passes
- Explain why ending away from origin while facing north is unbounded
- Handle long command strings in O(n)
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
- Return the radius of the smallest circle centered at the origin that contains the path.
- What if the drone can turn by 45 degrees instead of 90?
- What if some commands are G with distance k?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: a non-empty string over G, L, R. Output a boolean: true if the infinite repetition of the string keeps the drone within some fixed radius....
High-Level Design
Run one pass, tracking position and heading index 0..3. Afterwards:
- If the position is the origin, each pass returns there, so bounded.
- If the heading is not north, one pass is a rigid motion wit...