FastPrepElevator Scheduling Simulation

Elevator Scheduling Simulation

OpenAI logoOpenAI● MediumFULLTIMENEW GRADPHONE SCREEN

Problem statement

Simulate one elevator in a building with numFloors floors, numbered 0 to numFloors - 1. The elevator starts on floor 0 with direction UP and has no capacity limit. Return what it does in each tick.

How time works

Time moves in discrete steps called ticks. In each tick the elevator can do one of these:

  • Move up or down exactly one floor.
  • Stop to drop off passengers, board passengers, or both.

Either action takes a full tick, so the elevator cannot move and drop off or board in the same tick. Many passengers can get off and board during one stop. Changing direction takes no time. Passengers who reach their destination leave the simulation.

The problem statement continues
Pro

Examples

Example 1

numFloors = 4calls = ["0,2;0,3"]part = 1return = [[0,0,2],[1,0,0],[2,0,0],[2,1,0],[3,0,0],[3,1,0]]

This is the walk-through from the task. The elevator is on floor 0 going up, and two passengers wait to go to floors 2 and 3.

  1. Board the passengers on floor 0: [0,0,2].
  2. Move to floor 1: [1,0,0].
  3. Move to floor 2: [2,0,0].
  4. Drop off the passenger going to floor 2: [2,1,0].
  5. Move to floor 3: [3,0,0].
  6. Drop off the passenger going to floor 3: [3,1,0].

Each step takes one tick. Everyone is done, so the simulation ends after six ticks.

FastPrep Pro
Reported in 1 OpenAI interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 3 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week
See OpenAI hiring insights
CodePython 3
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 OpenAI interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 3 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week