-
Notifications
You must be signed in to change notification settings - Fork 5
/
RailwayStation.txt
48 lines (28 loc) · 976 Bytes
/
RailwayStation.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Railway Station
Problem Description
Given schedule of trains and their stoppage time at a Railway Station, find minimum number of platforms needed.
Note -
If Train A's departure time is x and Train B's arrival time is x, then we can't accommodate Train B on the same platform as Train A.
Constraints
1 <= N <= 10^5
0 <= a <= 86400
0 < b <= 86400
Number of platforms > 0
Input
First line contains N denoting number of trains.
Next N line contain 2 integers, a and b, denoting the arrival time and stoppage time of train.
Output
Single integer denoting the minimum numbers of platforms needed to accommodate every train.
Time Limit
1
Examples
Example 1
Input
3
10 2
5 10
13 5
Output
2
Explanation
The earliest arriving train at time t = 5 will arrive at platform# 1. Since it will stay there till t = 15, train arriving at time t = 10 will arrive at platform# 2. Since it will depart at time t = 12, train arriving at time t = 13 will arrive at platform# 2.