Decide Whether a Repeating Robot Instruction Loop Stays Bounded

Last updated: November 29, 2026

Quick Overview

A robot at the origin facing north repeats a command string of G (move forward one step), L (turn left) and R (turn right) forever; return whether it stays within some bounded circle.

Microsoft
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


A robot at the origin facing north repeats a command string of G (move forward one step), L (turn left) and R (turn right) forever; return whether it stays within some bounded circle.

A Microsoft phone screen simulation question that rewards a short proof over brute force. The interviewer checks that you simulate one pass of the instructions and then argue, rather than guess, why that single pass decides the answer.

What the Interviewer Expects
  • Simulate one pass with position and a direction index
  • Return true if the robot is back at the origin after one pass
  • Return true if it does not face north after one pass
  • Explain why at most four passes return it to the origin
  • Run in O(n) time and O(1) space
Key Topics to Cover
simulation
geometry
state machines
math
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 changes if instructions include a 'turn around' or move-back command?
  • How many passes until the robot first returns to the origin?
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 is a non-empty string over G, L, R. The robot starts at (0, 0) facing north. The string repeats forever. Return True if the set of visited positions is bounded, False if the robot drifts a...

High-Level Design

Simulate one pass to get the displacement (x, y) and the final heading. If the robot is back at the origin, every pass repeats the same loop, so it is bounded. If it ends facing north but displaced,...


Submit Your Answer
Markdown supported