FastPrepTotal Stops of an Elevator Serving a Queue
Problems/Total Stops of an Elevator Serving a Queue

Total Stops of an Elevator Serving a Queue

Expedia logoExpedia● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: One post, published on September 16, 2016 by a student who received an SDE internship offer from an Expedia campus drive, lists this task in the second face-to-face technical interview of that drive.

The post describes the elevator's limits and two input arrays, the weights and then the floors, and asks for the overall stop count. It gives no examples, sizes, or rules for the boarding order or the ground floor. Here, people board in the order given. A trip takes people from the front while both limits hold: at most X people, and a weight sum of at most Y. The elevator stops once at each different floor of its riders. The return to the ground floor ends a trip and counts as a stop. There are 1 to 3000 people, floors up to 10^9, and the weight limit can be as large as 2^31 - 1.

Our version is about 70% the same as the reported question.

An elevator serves a building with numFloors floors above the ground floor. People stand in a queue. Person i weighs weights[i] and wants to get off at floor floors[i].

The elevator makes trips from the ground floor. For each trip it takes people from the front of the queue, in order, as long as both limits hold:

  • at most maxPeople people ride together, and
  • their total weight is at most maxWeight.

During a trip the elevator stops once at each different floor that its riders want, then it goes back to the ground floor. Returning to the ground floor also counts as a stop. Then the next trip takes the next people in the queue, until nobody is left.

Return the total number of stops over all trips.

Function

elevatorStops(weights: int[], floors: int[], numFloors: int, maxPeople: int, maxWeight: int) → int

Examples

Example 1

weights = [70,50,80,100,60]floors = [2,3,2,5,5]numFloors = 6maxPeople = 3maxWeight = 200return = 5

Trip 1 takes the first three people: 70 + 50 + 80 = 200 is within the weight limit, and three people is the most allowed. They go to floors 2, 3 and 2, so the elevator stops at floors 2 and 3, then at the ground floor: 3 stops. Trip 2 takes 100 and 60 (160 in total). They both go to floor 5: 1 stop, then the ground floor: 2 stops. The total is 3 + 2 = 5.

Example 2

weights = [90,70,40,40,60,50]floors = [4,4,1,2,1,3]numFloors = 5maxPeople = 4maxWeight = 150return = 9

Trip 1 takes only the first person: adding the second would make 90 + 70 = 160, which is above 150. Floor 4, then ground: 2 stops. Trip 2 takes 70, 40 and 40, which is exactly 150; the next person would make it too heavy. Floors 4, 1 and 2, then ground: 4 stops. Trip 3 takes 60 and 50 (110), floors 1 and 3, then ground: 3 stops. The total is 2 + 4 + 3 = 9.

Example 3

weights = [10,10,10,10,10]floors = [3,1,3,1,3]numFloors = 4maxPeople = 5maxWeight = 1000return = 3

Everyone fits in one trip. The people go to floors 3, 1, 3, 1 and 3, which are only two different floors, so the elevator stops at floor 1 and floor 3 once each, then at the ground floor: 3 stops.

Constraints

  • 1 <= weights.length <= 3000, and floors.length == weights.length.
  • 1 <= numFloors <= 10^9 and 1 <= floors[i] <= numFloors.
  • 1 <= maxPeople <= 10^9 and 1 <= maxWeight <= 2^31 - 1.
  • 1 <= weights[i] <= maxWeight, so every person can ride alone.

More Expedia Onsite Interview questions

  • Scramble StringONSITE INTERVIEW · Seen Sep 2026
  • Smallest Sufficient TeamONSITE INTERVIEW · Seen Sep 2026
  • Check Anagram Pairs Index by IndexONSITE INTERVIEW · Seen Oct 2025
  • Fresh Oranges Left After Rotting StopsONSITE INTERVIEW · Seen Oct 2025
  • Longest Increasing SubsequenceONSITE INTERVIEW · Seen Oct 2025
  • Lowest Common Ancestor with Repeated and Missing ValuesONSITE INTERVIEW · Seen Oct 2025
  • Shortest Substring with Exactly K OnesONSITE INTERVIEW · Seen Oct 2025
  • Middle Element of a Linked ListONSITE INTERVIEW · Seen Nov 2024
  • Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
  • Mirror Image Binary TreesONSITE INTERVIEW · Seen Sep 2024

Similar questions at other companies

  • Latest Arrival Time for a ShuttleGoogle · ONSITE INTERVIEWGoogle interview questions
  • Assign Partitions to the Least-Loaded ServersAmazon · ONSITE INTERVIEW
  • Evaluate a Blackjack HandGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Team-Preferred Stable MatchingBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Climb Detection with Recoverable DipsStrava · PHONE SCREEN
  • Final Pod Counts After LogsSalesforce · OASalesforce interview questions
  • Experiment Bucket Allocation and RebalancingPinterest · PHONE SCREENPinterest interview questions
  • Automation Pipeline, Part 3: Stage DurationPlaid · PHONE SCREENPlaid interview questions
  • Generate an Optimal Portfolio Trading ReportPoint72 · PHONE SCREENPoint72 interview questions
  • Future-Aware Cache EvictionBenchling · PHONE SCREENBenchling interview questions

Expedia interview experiences

  • Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
  • Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
  • Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
  • Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
  • Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)
  • Expedia SWE Intern Final Round: 126 Experiences (Part 1 of 6)
All Expedia interview questionsSee Expedia hiring insights
Saved
class Solution {
    public int elevatorStops(int[] weights, int[] floors, int numFloors, int maxPeople, int maxWeight) {
        // Write your code here.
    }
}
Checking account…