Decide Whether a Looping Drone Patrol Stays Within a Bounded Area

Last updated: November 29, 2026

Quick Overview

A security drone over a fulfillment center yard starts at the origin facing north and repeats an instruction string forever, where G moves one unit forward, L turns left 90 degrees and R turns right 90 degrees. Return True if the drone stays inside some fixed circle forever.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Medium

0

0

0 solved


A security drone over a fulfillment center yard starts at the origin facing north and repeats an instruction string forever, where G moves one unit forward, L turns left 90 degrees and R turns right 90 degrees. Return True if the drone stays inside some fixed circle forever.

An Amazon phone screen state machine question. It looks like it needs infinite simulation, and the interviewer wants the argument that one or four passes of the instruction string decide the answer.

What the Interviewer Expects
  • Simulates position and heading for one pass
  • States the condition: back at origin or not facing north
  • Proves why a changed heading returns within four passes
  • Uses a direction vector table
  • Runs in O(len(instructions))
Key Topics to Cover
state machine
simulation
rotation
cycle reasoning
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Return the radius of the smallest circle that contains the path.
  • What if the drone can also turn 45 degrees?
  • How would you detect a bounded path when instructions are random per loop?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: string over {G, L, R}, length up to 100. Output: True if the trajectory of the infinitely repeated string is bounded....

High-Level Design

Simulate one pass, tracking (x, y) and heading index d in north, east, south, west order. After one pass there are two cases. If the drone is back at the origin, the path repeats exactly and is bounde...


Submit Your Answer
Markdown supported