Bird
Raised Fist0

Given the input arrivals = [900, 940, 950] and departures = [910, 1200, 1120], what is the value of max_platforms after processing the second train (index 1)?

easy🧾 Code Trace Q12 of Q15
Greedy Algorithms - Minimum Platforms (Train Stations)
Consider the following Python function that calculates the minimum number of platforms needed. Given the input arrivals = [900, 940, 950] and departures = [910, 1200, 1120], what is the value of max_platforms after processing the second train (index 1)?
A3
B1
C2
D0
Step-by-Step Solution
Solution:
  1. Step 1: Sort trains by arrival time

    Sorted trains: [(900, 910), (940, 1200), (950, 1120)]
  2. Step 2: Process trains up to index 1

    After first train: heap=[910], max_platforms=1 Second train arrival=940, heap top=910 ≤ 940, pop 910 Push 1200, heap=[1200], max_platforms=max(1,1)=1 Since question asks after second train, max_platforms=1
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Heap size after second train is 1, max_platforms updated to 1 [OK]
Quick Trick: Heap pops departures ≤ arrival before push [OK]
Common Mistakes:
MISTAKES
  • Not popping from heap before push
  • Confusing max_platforms update timing
  • Off-by-one in iteration
Trap Explanation:
PITFALL
  • Candidates often forget to pop platforms freed before pushing new train departure.
Interviewer Note:
CONTEXT
  • Tests ability to mentally execute heap-based scheduling code.
Master "Minimum Platforms (Train Stations)" in Greedy Algorithms

3 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Greedy Algorithms Quizzes