Legendary Magician
Practice
4.5 (2 votes)
Algorithms
Greedy algorithms
Basics of greedy algorithms
Greedy algorithm
Problem
25% Success 1300 Attempts 30 Points 3s Time Limit 256MB Memory 1024 KB Max Code

Legendary magician, Dynamo has a special magic trick that he wants to show to every student in College. But as this is placement time, every student is busy with preparation, so everyone can't be present at the magic show at the same time. There are \(N\) students in college, and the \(i^{th}\) student reaches the magic show at a time \(A_i\) and leaves at time \(B_i\) . As special trick is so special, he doesn't want to play it frequently. So, Dynamo wants to know the minimum number of times he would have to show his special trick so that every student in college can watch this.

Note: To play the magic trick, he takes \(0\) seconds.

 

Input Format

The first line of the input contains an integer \(T\), denoting the number of test cases.

The first line of test case contains a single integer \(N\) - denoting the length of array \(A\) and \(B\).

The second line of test case contains \(N\) space separated integers, \(A_1,A_2,A_3,....,A_N\)

The third line of test case contains \(N\) space separated integers, \(B_1,B_2,B_3,....,B_N\)

 

Output Format

Return an integer denoting the minimum number of times Dynamo would have to play his special trick .

 

Constraints

\(1 \leq T \leq 100 \\ 1 \leq N \leq 10^5 \\ 1 \leq A[i] < B[i] \leq 10^9 \)

Both \(A[i]\) and \(B[i]\) are inclusive.

The sum of \(N\) over all test cases does not exceed \(10^5\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
1 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsC++Greedy Algorithms
Points:30
32 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsC++Greedy Algorithms
Points:50
43 votes
Tags:
TrieApprovedMedium-HardGreedy algorithm