← Questions

Robot charging controller with exclusive stations

0
AmazonCodingLast asked Jan 2026

A coding interview question asked in Amazon's technical phone screen, last asked Jan 2026. It tests simulation, state machines and concurrency.

A fleet of robots shares a small number of charging stations. A robot whose battery is below 50% should go to a free station; a robot that is charging and is above 95% may leave and go back to work. Write the controller function that decides this. It is called several times a second, and the APIs that read battery levels and command robots already exist: the question is how the controller uses them and keeps track of assignments between calls.

Interface

Unless you agree on a different interface with the interviewer, assume:

  • battery(robot_id) -> float | None — the latest battery percentage, or None when there is no reading.
  • send_to_station(robot_id, station_id, op_id) -> bool and send_to_work(robot_id, op_id) -> bool — return once the robot has accepted the command, not when it has arrived; op_id makes a retried command idempotent.
  • station_status(station_id) -> "free" | "occupied" | "offline" and robot_location(robot_id).
  • tick() -> None — your controller, called repeatedly.

Rules

  • The thresholds are strict: exactly 50% does not start charging, exactly 95% does not end it.
  • A station holds at most one robot and a robot holds at most one station.
  • Repeated calls must never dispatch the same robot twice, give one station to two robots, or resend "back to work" every call.
  • When no station is free, robots that need charge wait. Choose and state a waiting policy (for example lowest battery first).

Part 1: state

Describe what the controller remembers between calls: each robot's state (working, waiting, heading to a station, charging, leaving) and each station's (free, reserved, occupied, offline). Keep the battery rule separate from the assignment state, and keep each waiting robot in the queue once.

Part 2: one call

Walk through one tick: read status, notice robots that have actually left their station, free those stations, release robots above 95%, then hand free stations to waiting robots. Say when state changes relative to each API call, including a robot finishing while others wait.

Part 3: repeated calls and failures

Explain what happens when calls overlap, a battery reading is missing or stale, or a command times out after it may have been accepted. Give the work per call and the state kept.

Clarifying questions

  • Which APIs report station occupancy and a robot's arrival or departure?
  • Does a successful command mean accepted or completed, and can its status be queried after a timeout?
  • Can a robot or station become unavailable while an assignment is pending?
  • Must the controller survive a restart without losing assignments in progress?

What a strong answer covers

  • A clear state machine per robot and per station, with the station reserved before dispatch and held until the robot is seen leaving, not when "back to work" is accepted.
  • The 50% / 95% gap working as hysteresis, and exact threshold values handled as stated.
  • Reservations changed atomically, with network calls made outside any long-held lock; at most one command in flight per robot.
  • Unknown or stale status reconciled rather than treated as "free".
  • Cost per call O(robots + stations) plus O(log) per queue operation.

Follow-ups

  • The controller restarts while robots are on their way to or from stations. How does it rebuild its assignments?
  • Several controller processes run at once. Where must the exclusive reservation be enforced?
  • Battery readings and acknowledgments arrive late. How do you keep a waiting robot's assignment correct without making an occupied station look free?

Where it's asked

  • Amazon · Technical phone screen · Last asked Jan 202660 min · Live coding in a shared editor that does not run code, plus Leadership Principles questions · No AI

What it tests

simulation · state machines · concurrency

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding