


1. The array follows 0-based indexing, so you need to return 0-based indices.
2. If 'x' is not present in the array, return {-1 -1}.
3. If 'x' is only present once in the array, the first and last position of its occurrence will be the same.
Input: arr = [1, 2, 4, 4, 5], x = 4
Output: 2 3
Explanation: The given array’s 0-based indexing is as follows:
1 2 4 4 5
↓ ↓ ↓ ↓ ↓
0 1 2 3 4
So, the first occurrence of 4 is at index 2, and the last occurrence of 4 is at index 3.
The first line contains the integer 'n', denoting the size of the sorted array.
The second line contains 'n' space-separated integers denoting the array elements.
The third line contains the value 'x', whose first and last position of occurrence you need to find.
The only line of output should contain two space-separated integers, where the first and second integer will be the first and the last position of occurrence of 'x', respectively, in the array.
1 <= n <= 10^4
-10^9 <= arr[i] <= 10^9
-10^9 <= x <= 10^9
Time Limit: 1sec
Try to solve the problem in O(log(N)) time complexity.
a. If ‘MID’ equals to 0 or if ARR[MID] == ‘X’, and 'X' > ARR[MID-1], return MID.
b. Else if, ‘X’ > ARR[MID], then set ‘LO’ = ‘MID’+1.
c. Else ‘X’ < ARR[MID], then set 'HI' = ‘MID’-1.
4. Else return -1.
a. If ‘MID’ equals to ‘N’-1 or if ARR[MID] == ‘X’, and ‘X’ < ARR['MID'+1], return 'MID'.
b. Else if, ‘X’ < ARR[MID], then set ‘LO’ = ‘MID’-1.
c. Else 'X' > ARR[MID], then set ‘HI’ = ‘MID’+1.
4. Else return -1.