Time-Ordered Elevator Dispatch
Reported by candidates from Pinterest's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Pinterest reportedly put a time-ordered elevator dispatch problem in an OA in September 2026, and the detail that trips people is that the floor line has no endpoints. Elevators never stop or bounce, they just keep drifting in their direction until a later assignment resets them. It's a pure simulation: no clever data structure, just careful state tracking. If you've got an invite for this one, the work is reading the eligibility rules precisely and not overthinking. And if you blank mid-assessment, StealthCoder runs invisibly on your desktop and can hand you the loop.
The problem
You are given the starting floors of several elevators and a time-ordered sequence of passenger events. Every elevator starts idle. Passenger i appears at floor requestFloors[i], requests direction requestDirections[i], and is processed at absolute time requestTimes[i]. Direction 1 means up and -1 means down. Process passengers in input order. Before processing each passenger, advance every moving elevator by one integer floor per unit of elapsed time in its current direction. Idle elevators stay at their current floors. The floor line has no endpoints. An elevator is eligible under these rules: An idle elevator is always eligible. An elevator moving up is eligible only when the passenger also requests up and the passenger floor is at or above the elevator's current floor. An elevator moving down is eligible only when the passenger also requests down and the passenger floor is at or below the elevator's current floor. Assign the nearest eligible elevator by absolute floor distance. If several eligible elevators are equally near, choose the smaller original index. If no elevator is eligible, the passenger is unserved and the ordinary time advance is the only state change. After an assignment, reset the selected elevator's modeled floor to the passenger's origin and set its direction to the passenger's requested direction. Travel to the pickup is outside this simulation and consumes no simulated time. The elevator continues in that direction until a later assignment changes it. Passengers with equal times are processed in input order. Return the index of the elevator assigned to the final passenger, or -1 if the final passenger is unserved. Function dispatchFinalPassenger(elevatorFloors: int[], requestFloors: int[], requestDirections: int[], requestTimes: int[]) → int Examples Example 1 elevatorFloors = [0,10] requestFloors = [2,8,6] requestDirections = [1,-1,-1] requestTimes = [0,2,4] return = 1 At time 0, elevator 0 is closest to floor 2, so it is assigned and begins moving up from floor 2. At time 2 it has reached floor 4, but it is ineligible for a down request. Idle elevator 1 is assigned at floor 8 and begins moving down. At time 4 both elevators are at floor 6, but only elevator 1 matches the final down request, so the result is 1. Example 2 elevatorFloors = [0,10,20] requestFloors = [5,15] requestDirections = [1,1] requestTimes = [0,0] return = 1 The first request is equally distant from elevators 0 and 1, so index 0 wins. No time elapses before the second request. Elevators 1 and 2 are both five floors away and idle, so the smaller index 1 serves the final passenger. Example 3 elevatorFloors = [0] requestFloors = [0,-1] requestDirections = [1,-1] requestTimes = [0,1] return = -1 Elevator 0 accepts the first up request. By time 1 it is at floor 1 and still moving up, so it is ineligible for the final down request at floor -1. The final passenger is unserved. Constraints 1 <= elevatorFloors.length <= 200 1 <= requestFloors.length <= 2000 requestDirections.length == requestFloors.length requestTimes.length == requestFloors.length -10^6 <= elevatorFloors[i], requestFloors[i] <= 10^6 requestDirections[i] is either -1 or 1. 0 <= requestTimes[i] <= 10^9 requestTimes is nondecreasing.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is that there is no trick. Constraints are 200 elevators and 2000 requests, so an O(requests x elevators) simulation is fine, about 400k steps. Keep two arrays: floor and direction (0 for idle). For each passenger, compute dt as the current time minus the previous time, then move each non-idle elevator by direction times dt. Don't advance before the first passenger, since elevators start idle anyway. Then scan for eligible elevators. Idle is always eligible. Up-moving needs an up request with passenger floor >= elevator floor. Down-moving needs a down request with passenger floor <= elevator floor. Pick the smallest distance, and break ties with the smaller index by scanning in order and using strict less-than. The common pitfalls are forgetting that an assigned elevator keeps moving afterward, and mishandling equal times where dt is zero. Track the last result and return it for the final passenger. StealthCoder is your hedge if the eligibility conditions get tangled live.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Time-Ordered Elevator Dispatch cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Pinterest's OA.
Pinterest reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Time-Ordered Elevator Dispatch FAQ
How hard is the Pinterest elevator dispatch OA really?+
Easier than it looks. It's a straight simulation with small constraints, so brute force passes. The difficulty is reading the rules correctly, especially eligibility for moving elevators and the tie-break. Code it slowly, then walk through the three examples by hand before submitting.
What's the pattern or trick for this problem?+
Simulation. Store each elevator's floor and direction, advance by direction times elapsed time before each request, then linearly scan for the nearest eligible elevator. No heap or sorting is needed. Strict less-than while scanning in index order handles the tie-break for free.
Do I need a faster algorithm than O(requests x elevators)?+
No. With at most 200 elevators and 2000 requests, you do about 400,000 checks. That's trivial. Don't waste your time on spatial indexes or priority queues. Spend it on edge cases like equal request times and unserved passengers.
What edge cases should I test?+
Equal timestamps, so no elapsed time. Negative floors, since the line has no endpoints. An elevator moving up while the request is below it, which makes it ineligible. All elevators ineligible for the final passenger, returning -1. Also large times up to 10^9, which fit in 64-bit math safely.
How do I prepare for this in 48 hours?+
Write the simulation once from scratch and trace Example 1 by hand. Then practice reading long rule-based statements and turning each rule into one condition. Simulation OAs reward careful reading more than algorithm knowledge, so rehearse that skill rather than memorizing patterns.