01Phone Screenwith Software EngineerTechnical60 minMedium
Interviewer: Software Engineer
First round was a pair programming question where I was asked to navigate a robot around a room.
Question:
You’ve got a Roomba in a room laid out as a grid. Each cell is either empty or blocked. The roomba can move forward, turn left, or turn right, but if it encounters a blocked cell it’ll bump into it and stay put. The goal is to get the robot to clean every accessible cell in the grid using only these movements.
// rotates/turns by 90 degrees
def turn_left()
def turn_right()
// cleans the current cell
def clean()
// moves the roomba forward
def move()
room = [
[1, 1, 1, 1], # Row 0
[1, 0, 0, 1], # Row 1
[1, 1, 1, 1], # Row 2
[1, 0, 1, 1] # Row 3
]
# 1: Accessible cell
# 0: Blocked cell
# starting position of the Roomba
row = 2
col = 2