Simulate a LOOK-Scheduled Elevator Serving Timed Floor Requests

Last updated: November 29, 2026

Quick Overview

A single elevator starts idle at floor 0 at time 0 and moves one floor per second. Requests (time, floor) arrive over time; the elevator keeps moving in its current direction while any pending stop lies ahead, reverses when none do, and idles when nothing is pending. Return the time each request is served.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


A single elevator starts idle at floor 0 at time 0 and moves one floor per second. Requests (time, floor) arrive over time; the elevator keeps moving in its current direction while any pending stop lies ahead, reverses when none do, and idles when nothing is pending. Return the time each request is served.

A Google onsite simulation question where the real test is making the policy precise and the time loop correct. Interviewers look for an explicit state (position, direction, pending stops), event ordering within a second, and jumping over idle time rather than ticking.

What the Interviewer Expects
  • Pin down the policy, tie-breaks, and what happens when a request arrives at the current floor
  • Maintain pending requests grouped by floor
  • Decide direction from pending stops ahead and behind
  • Skip idle gaps by jumping to the next arrival
  • Analyze cost in terms of travel time plus requests
Key Topics to Cover
discrete event simulation
state machine
scheduling
elevator algorithm
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
  • Add door dwell time at each stop and requests that arrive while doors are open.
  • How would you dispatch across a bank of four elevators?
  • How would you minimize average wait instead of using LOOK?
  • How would you test this simulator against a brute force reference?
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

Inputs: list of (time, floor) requests, any order. The elevator at time t on floor p first absorbs arrivals with time <= t, then serves every pending request for floor p at time t. If nothing is p...

High-Level Design

State: t, pos, dir, a pointer into requests sorted by time, and pending: floor -> list of ids. Each iteration of the main loop is one second of motion or one jump: absorb arrivals, serve the c...


Submit Your Answer
Markdown supported