Ninja is the manager of a restaurant. There were ‘N’ customers who visit the restaurant. Ninja is interested in calculating what was the maximum number of customers in the restaurant at a time. He finds this problem is tough for him, so he wants your help.
You are given the arrival and leaving time of ‘N’ customers in the form of arrays named ‘ARRIVAL’ and ‘LEAVING’. Your task is to find the maximum number of customers at any point in time.
Note :All arrival and leaving times are distinct.
The first line contains an integer ‘T’, which denotes the number of test cases to be run. Then, the T test cases follow.
The first line of each test case contains a positive integer, ‘N’, denoting the total number of customers.
The next ‘N’ lines of each test case contain 2 integers, ‘x’, and ‘y’, denoting the arrival and leaving time of a customer.
Output Format :
For each test case, print the “maximum number of customers” in the restaurant at a time, as described in the problem statement.
Output for each test case will be printed in a separate line.
Note :
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= ‘T’ <= 10
1 <= ‘N’ <= 10^4
1 <= ‘x’ < ‘y’ <= 10^6
Time Limit: 1 second
1
2
1 3
4 5
1
Customer 1 arrives at ‘1’ and leaves at ‘3’. So, the maximum number of customers at that time is only ‘1’. Now the 2nd customer arrives at ‘4’ and leaves at ‘5’. So, the maximum number of customers remains ‘1’ only.
1
2
2 5
1 3
2
Try to find for each time individually.
O(M * N), where ‘N’ is the number of customers, and ‘M’ is 10^6.
We are running a loop through all the possible unit times. In each iteration, we are traversing through all the customer’s data that of size N. In the worst-case the final leaving time, let it be M would be 10^6. So, the time complexity will be O(M*N).
O(1)
As we are only using constant space.