Simulate a LOOK Elevator Serving Timed Floor Requests

Last updated: November 29, 2026

Quick Overview

Simulate a single elevator that moves one floor per time unit and follows the LOOK policy (keep moving in the current direction while requests remain ahead, otherwise reverse or idle), and return the floor and time at which each request is served.

Microsoft
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Simulate a single elevator that moves one floor per time unit and follows the LOOK policy (keep moving in the current direction while requests remain ahead, otherwise reverse or idle), and return the floor and time at which each request is served.

A Microsoft onsite simulation question, often given as an object-oriented or state machine exercise. The interviewer is checking that you define the rules precisely before coding, keep time advancing correctly (including idle gaps), and avoid infinite loops when requests arrive mid-trip.

What the Interviewer Expects
  • Pin down movement, arrival and tie-breaking rules before writing code
  • Model the elevator as state: time, floor, direction and pending requests
  • Absorb requests as their arrival time is reached
  • Jump time forward when idle instead of ticking one by one
  • Explain why the loop always terminates
Key Topics to Cover
simulation
state machines
scheduling
event processing
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
  • How would you extend this to a bank of elevators with a dispatcher?
  • How would you add door open and close times and capacity limits?
  • How would you test the simulation for starvation of far floors?
  • How would you turn this into an event-driven simulation?
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

Rules to confirm with the interviewer:

  • The elevator starts idle at start_floor at time 0 and moves exactly one floor per time unit.
  • A request (time, floor) becomes known at its arrival time. ...
High-Level Design

The state is (t, floor, direction, pending), plus a pointer into the requests sorted by time. Each loop iteration is one tick: absorb any requests that have arrived, serve the current floor if it is...


Submit Your Answer
Markdown supported