First and Last Occurrence in Sorted Array
Find the first and last positions of a target value in a sorted array with duplicates.
Input format
The first line contains N and the target. The second line contains N integers in non-decreasing order (duplicates allowed).
Output format
Print the first and last 0-based positions of the target separated by a space, or -1 -1 if it does not occur.
Constraints
- Values fit in a 64-bit signed integer
- Trailing whitespace and a trailing newline are ignored by the judge
Read from stdin, write to stdout. Sample cases below show the exact format.
Sample cases
Example 1
Input
6 8
5 7 7 8 8 10Expected output
3 4Example 2
Input
6 6
5 7 7 8 8 10Expected output
-1 -1