Given a sorted array and a number key, find the index of the first and last occurrence of the key in the array.
If the key is not present, return [-1, -1].
Expected Time Complexity: O(log n)
Array: [1, 2, 3, 3, 3, 4, 4, 5]
Number: 3
Answer: [2, 4]
Array: [1, 2, 3, 3, 3, 4, 4, 5]
Number: 5
Answer: [7, 7]
Array: [1, 2, 3, 3, 3, 4, 4, 5]
Number: 6
Answer: [-1, -1]
First-line contains an integer âTâ denoting the number of test cases.
For each test case the input has two lines:
T lines each contain two integers denoting the indices of the first and last occurrence of the key in the array for each test case.
2
8 3
1 2 3 3 3 4 4 5
8 6
1 2 3 3 3 4 4 5
2 4
-1 -1
1 <= T <= 100
1 <= n <= 104
-106 <= Ai <= 106
-106 <= key <= 106