FastPrepMinimum Railway Platforms

Minimum Railway Platforms

MakeMyTrip.com logoMakeMyTrip.com● MediumFULLTIMEONSITE INTERVIEW
Learn

Problem statement

Given equal-length arrays of train arrival and departure times, return the minimum number of station platforms required so that no train waits.

Each pair at the same index describes one train. Time values are comparable integers on one day. If one train arrives at the exact time another departs, both occupy a platform at that instant, so the arrival is processed first.

Function

minimumPlatforms(arrivals: int[], departures: int[]) → int

Examples

Example 1

arrivals = [900,940,950,1100,1500,1800]departures = [910,1200,1120,1130,1900,2000]return = 3

Three trains overlap around time 1100.

Example 2

arrivals = [900,1100,1235]departures = [1000,1200,1240]return = 1

No two train intervals overlap.

Constraints

  • 1 <= arrivals.length == departures.length <= 200000
  • 0 <= arrivals[i] <= departures[i] <= 10^9
  • All times belong to one comparable timeline.

Source note: Interview prompt excerpt preserved as source evidence.

More MakeMyTrip.com problems

See MakeMyTrip.com hiring insights
public int minimumPlatforms(int[] arrivals, int[] departures) {
    // Write your code here.
}
arrivals[900,940,950,1100,1500,1800]
departures[910,1200,1120,1130,1900,2000]
expected3
Checking account…