
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 single integer, ‘N’, denoting the total number of sessions. Then ‘N’ lines follow.
Each of these ‘N’ lines contains two space-separated integers, denoting the starting time and ending time of the ‘ith’ session.
For each test case, print a single integer, denoting the maximum number of sessions Ninja can attend.
Output for each test case will be printed in a separate line.
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^5
1 <= A,B, <= 10^9
Time Limit: 1sec
The approach is to observe that to maximize the total number of sessions that Ninja can attend, it is always beneficial to attend the session that ends the earliest. So, we can sort all the sessions according to the non-decreasing order of their ending time. We can define a variable to keep track of the time at which the session which Ninja is currently attending ends. Now, we can loop through all the sessions and if a session starts at a time later than the time at which the current session ends, then Ninja will be able to attend this session and we increase the value of our final answer by 1.