
A half open interval [left, right) denotes all real number left <= x < right.
1 -> addRange(left, right)
2 -> queryRange(left, right)
3 -> removeRange(left,right)
1 10 20
3 14 16
2 10 14
2 13 15
2 16 17
Here the outputs will be -1, -1, true, false, true as -
In the first query range [10,20), it is being tracked. After that, in second query range [14,16) is removed. So the range being tracked becomes [10,14) U [16,20).
In the third query, we are checking if [10,14) range is being tracked so we will return true.
In the fourth query, we are checking if [13,15) is being tracked so will return false.
In the fifth query, we are checking if [16,17) is being tracked, so we will return true.
The first line of input contains an integer ‘T’ denoting the number of test cases to run. Then the test case follows.
The first line of each test case contains an integer ‘Q’ denoting the number of queries to be answered.
Then the next 'Q' lines contain three space-separated integers the first integer representing the type of query and two integers left and right.
For each test case, for all the call of the query of type:-
1- add the half-open interval [left, right). We print -1 whenever this operation is called.
2- return true or false
3- remove the half-open interval [left,right). We print -1 whenever this operation is called.
You don’t need to print anything or take input. This already has been taken care of. Just implement the function.
1 <= T <= 10
0 < left < right < 10^9 in all calls to addRange, queryRange, removeRange.
The total number of calls to 1st query in a single test case is at most 1000.
The total number of calls to 2nd query in a single test case is at most 5000.
The total number of calls to 3rd query in a single test case is at most 1000.
Time limit - 1sec
Approach:
Use a map to save the disjoint intervals. For example, M['LEFT'] = 'RIGHT' means there is an interval ['LEFT', 'RIGHT').
Algorithm:
Define one map ‘M’
Vertical Order Traversal of Binary Tree
Longest String Chain
Longest String Chain
Uniform K-Subarray Sums
First Repeating Element
Alphabetical Character Frequency