Track a Cleaning Robot's Farthest Distance Around Furniture Obstacles

Last updated: November 29, 2026

Quick Overview

A home cleaning robot starts at (0, 0) facing north and receives commands: -2 turns left, -1 turns right, and a positive k moves k unit steps forward, stopping before any obstacle cell. Return the maximum squared Euclidean distance from the origin the robot ever reaches.

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

0

0

0 solved


A home cleaning robot starts at (0, 0) facing north and receives commands: -2 turns left, -1 turns right, and a positive k moves k unit steps forward, stopping before any obstacle cell. Return the maximum squared Euclidean distance from the origin the robot ever reaches.

A common Google phone screen warm-up in the style of a Nest-like home robot. The interviewer wants a clean direction-vector simulation, an O(1) obstacle lookup, and attention to the detail that blocked moves stop early rather than skip.

What the Interviewer Expects
  • Represent heading as an index into a direction array instead of if/else chains
  • Store obstacles in a hash set of tuples for O(1) checks
  • Move one unit at a time so an obstacle mid-move stops the robot
  • Track the max squared distance at every step, not just the end
  • State time as O(total steps + obstacles)
Key Topics to Cover
simulation
direction vectors
hash set
grid movement
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
  • What if k can be as large as 10^9? How do you avoid stepping one cell at a time?
  • How would you return the full path for a debugging overlay?
  • How does the solution change if the robot can also move backward?
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: a list commands of integers and a list obstacles of [x, y] pairs. The robot faces north at the origin. -2 turns left 90 degrees, -1 turns right 90 degrees, and k > 0 moves forward u...

High-Level Design

Keep dirs = [(0,1),(1,0),(0,-1),(-1,0)] in clockwise order. A right turn is d = (d+1) % 4, a left turn is d = (d+3) % 4. For a move, step one cell at a time: compute the next cell, and if it is ...


Submit Your Answer
Markdown supported