Decide Whether a Looping Robot Path Stays Within a Bounded Area

Last updated: November 29, 2026

Quick Overview

A warehouse robot starts at the origin facing north and repeats an instruction string of G (move one step), L (turn left) and R (turn right) forever. Return whether the robot stays within some bounded circle.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


A warehouse robot starts at the origin facing north and repeats an instruction string of G (move one step), L (turn left) and R (turn right) forever. Return whether the robot stays within some bounded circle.

A Meta screen simulation question with a neat invariant. The interviewer checks that you simulate one pass, then argue from the final position and heading instead of simulating forever.

What the Interviewer Expects
  • Simulate one pass with a direction vector
  • Show that ending at the origin means bounded
  • Show that ending facing a different direction means bounded within four passes
  • Show that facing north away from the origin means unbounded drift
  • Give O(n) time and O(1) space
Key Topics to Cover
Simulation
Direction vectors
Invariants
Geometry
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
  • How many passes until the robot is guaranteed back at the origin?
  • What if there are obstacles that block moves?
  • How would you return the bounding box of the path?
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 1..100. The robot repeats it infinitely. Output: True if positions stay bounded, False otherwise....

High-Level Design

Simulate the string once with direction index d in 0..3 (N, E, S, W), dirs = [(0,1),(1,0),(0,-1),(-1,0)], where R is d = (d + 1) % 4 and L is d = (d + 3) % 4.

After one pass with displacement v...


Submit Your Answer
Markdown supported