170. First and Last Occurrence
EasyBinary Search
Print the first and last 0-based index of x in the sorted array, or -1 -1 if absent.
Input format
Line 1: n Line 2: n sorted integers Line 3: x
Output format
first last
Example 1
Input
6 5 7 7 8 8 10 8
Output
3 4
Example 2
Input
6 5 7 7 8 8 10 6
Output
-1 -1
Constraints
1 ≤ n ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.
Loading the MyLoginn IDE…