Trains and Platforms

Medium

You are given the arrival and departure times for n trains at a railway station. Find the minimum number of platforms the railway station needs so that none of the trains have to wait.

The time is given in minutes from midnight. All trains have departures on the same day.

Example:
Trains (arrival, departure): [(120, 130), (130, 150), (125, 145), (150, 180)]
Output: 3
Explanation: At 2:10 AM (130th minute), there are 3 trains at the station.

Testing

Input Format

The first line contains an integer ‘T’ denoting the number of test cases.

For each test case, the input contains the following lines:

  • The first line contains an integer n denoting the number of trains.
  • The next n lines, each have two space-separated integers- arrivali and departurei denoting the arrival and departure times of the ith train on each day.

Output Format

One line for each test case, with the minimum number of platforms required.

Sample Input

2
4
120 130
130 150
125 145
150 180
7
360 400
320 380
260 320
210 250
420 450
440 480
370 420

Expected Output

3
3

Constraints

1 <= t <= 10
1 <= n <= 5*104
0 <= arrivali < departurei < 1440

Companies
Editorial Link: Editorial