An append-only event log stores timestamps in a single list sorted in non-decreasing order (the same timestamp may repeat). Given a target timestamp x, report the first and the last 0-indexed positions at which x appears. If x does not appear at all, report -1 -1.
Line 1: an integer n, the number of timestamps.
Line 2: n space-separated integers in non-decreasing order.
Line 3: an integer x, the target timestamp.
Two space-separated integers on one line: the first and last 0-indexed positions of x, or -1 -1 if x is absent.
Example 1
Input
7 1 2 2 2 5 5 8 2
Expected
1 3
Explanation
The value 2 first appears at index 1 and last appears at index 3.
Example 2
Input
5 1 3 5 7 9 4
Expected
-1 -1
Explanation
The value 4 never appears, so the answer is -1 -1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →