2dbi
Home/ServiceNow/Minimum Number of Platforms
SServiceNow·DSAIC2Technical Phone Screen

Minimum Number of Platforms

Problem

Given train arrival and departure times, find the minimum number of platforms needed so no train waits.

Example

arr=[900,940,950,1100], dep=[910,1200,1120,1130] -> 3

Constraints

  • 1 ≤ n ≤ 10^5

Approach

Sort arrivals and departures; sweep with two pointers tracking concurrent trains. Reported ServiceNow question.

added 6 days ago
LeadersAccount