KatInterview

Single-Elevator Control Policy for a Four-Stop Building

System DesignModel answer
MediumModel answerSystem Designelevatorschedulingstate-machine

Last updated

Design the scheduling logic for one elevator serving a basement plus three floors, covering objectives, state, dispatch strategy, data structures, and simulation.

The Problem

You are building the control software for a single elevator in a small building. The car stops at exactly four floors: B (basement), 1 (lobby), 2, and 3. There are no other stops.

Your job is to design the scheduling policy: the logic that decides, at every decision point, where the elevator should go next. This is not a hardware or distributed-systems problem — the interesting work is the decision policy, the state it depends on, and how you know the policy is good.

Address each of the following areas:

1. Objectives

What are you optimizing? Name the metrics (wait time, system time, tail latency, starvation), put rough numbers on them where useful, and explain the tensions between them.

2. Physical and operational constraints

What limits does the real world impose? Cover car capacity, travel times, door mechanics, safety interlocks, and anything else the scheduler must respect or treat as a hard boundary.

3. Inputs and internal state

What does the controller observe (calls, position, load, door state, mode signals)? What state does it maintain between decisions?

4. Dispatch strategy

How does the controller pick the next stop? Walk through your baseline algorithm, then layer on refinements: peak-traffic handling, anti-starvation, capacity-aware skipping, idle parking, and any optional enhancements. Justify each refinement with an argument about when it helps and when it is not worth the complexity.

5. Data structures and state machine

What concrete data structures back the logic? Sketch the controller's state machine with its key transitions.

6. Simulation and validation

How would you test that your policy is actually better than a simpler one? Describe the traffic scenarios, metrics, and validation approach.

A strong answer puts numbers on the physics early, spends most of its time on the policy and its trade-offs, and closes with a credible way to measure whether the policy works.

Hints

Hint 1

Start by sizing the physics: how long does a full B→3 round trip take? That number tells you whether routing cleverness or door/stop overhead is the bigger lever.

Hint 2

Think about what the elevator should do when there are no pending calls — the parking decision is one of the highest-value choices in a small building with bursty traffic.

Hint 3

Starvation is a policy correctness property, not just a performance property. Explain how your strategy guarantees every call is eventually served, not just how it usually serves calls quickly.