Description
Given arrival and departure times of all trains that reach a railway station. Your task is to find the minimum number of platforms required for the railway station so that no train waits.
Note: Consider that all the trains arrive on the same day and leave on the same day. Also, arrival and departure times must not be same for a train.
Input
The first line of input contains T, the number of test cases. For each test case, first line will contain an integer N, the number of trains. Next two lines will consist of N space separated time intervals denoting arrival and departure times respectively.
Note: Time intervals are in the 24-hourformat(hhmm), preceding zeros are insignificant. 200 means 2:00.
Consider the example for better understanding of input.
Constraints:1 <= T <= 100,1 <= N <= 1000,1 <= A[i] < D[i] <= 2359
Output
For each test case, print the minimum number of platforms required for the trains to arrive and depart safely.
Sample Input 1
1
6
900 940 950 1100 1500 1800
910 1200 1120 1130 1900 2000
Sample Output 1
3
# 到站数组、出站数组、车辆数
def solution(l1, l2, number):
# 不用管到站、出战的是哪辆车,只要关注时间点就可以
# 某个时间点有车进站,必须要有站台,某个时间点出战,可以腾出站台来
l1.sort()
l2.sort()
# 实时车站需要量
plat_need = 1
# 最大需要量
result = 1
# i表示第几个进站,j表示第几个出站
i = 1
j = 0
while i < number and j < number:
# 下一辆车的到站时间比前一辆车的出站时间早,站台数+1
if l1[i] < l2[j]:
plat_need += 1
i += 1
if plat_need > result:
result = plat_need
else:
# 当l1[i] == l2[j]时,先出站,plat_need-1,执行到下次while循环时再进站
plat_need -= 1
j += 1
return result
if __name__ == '__main__':
n = int(input())
for i in range(n):
number = int(input())
l1 = list(map(int, input().strip().split()))
l2 = list(map(int, input().strip().split()))
result = solution(l1, l2, number)
print(result)