At 1100 arrival, trains at station are 3 (940-1200, 950-1120, 1100-1130 overlap). So minimum platforms = 3.
Final Answer:
3 -> Option A
Quick Check:
Max overlap = 3 platforms [OK]
Hint: Sort times and count overlaps to find max platforms [OK]
Common Mistakes:
Not sorting times before processing
Counting total trains instead of overlaps
Mixing arrival and departure times
4. Identify the bug in this Rust function snippet for minimum platforms calculation:
fn min_platforms(arrivals: Vec<i32>, departures: Vec<i32>) -> i32 {
let mut arr = arrivals.clone();
let mut dep = departures.clone();
arr.sort();
dep.sort();
let mut platform_needed = 1;
let mut max_platforms = 1;
let mut i = 1;
let mut j = 0;
while i < arr.len() && j < dep.len() {
if arr[i] <= dep[j] {
platform_needed += 1;
i += 1;
} else {
platform_needed -= 1;
j += 1;
}
if platform_needed > max_platforms {
max_platforms = platform_needed;
}
}
max_platforms
}
medium
A. Using clone() causes runtime error
B. Sorting departures is unnecessary
C. Starting i from 1 skips first arrival comparison
D. The loop condition should be OR instead of AND
Solution
Step 1: Check loop initialization
Variable i starts at 1, skipping the first arrival time comparison which can cause incorrect platform count.
Step 2: Understand impact of skipping first arrival
Missing the first arrival means initial platform count may be wrong, leading to incorrect max platforms.
Final Answer:
Starting i from 1 skips first arrival comparison -> Option C
Quick Check:
Indexing from 1 skips first train [OK]
Hint: Start indices at 0 to include all trains [OK]
Common Mistakes:
Ignoring index start positions
Thinking sorting is unnecessary
Confusing clone() with error cause
5. Given arrival times [100, 140, 150, 200, 215, 400] and departure times [110, 300, 220, 230, 315, 600], what is the minimum number of platforms needed? Explain why this number is required.