Loading...
Loading...
A mock-test app stores all your attempt scores, sorted from low to high. The same score can appear many times.
For a score t, print the index of its first copy and the index of its last copy, counting from 0. If t never appears, print -1 -1.
-1 -1.Example 1
Input
7 55 40 55 55 55 62 70 70
Output
1 3
55 appears at indices 1, 2 and 3.
Example 2
Input
4 50 10 20 60 80
Output
-1 -1
50 does not appear.
Try the problem first. Open one hint at a time.
Searching once and stopping at any copy of t is not enough. You need the two ends of the run.
Do two searches. The first one keeps going left after it finds t; the second keeps going right.
In the first search, when the middle equals t, save it and continue with hi = mid - 1.
Another way: the last copy of t is just before the first score that is at least t + 1.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor