Loading...
Loading...
Loading...
Arjun posts a coding reel. For n days, its daily views go strictly up and then strictly down, like a mountain. The highest day is never the first or the last day.
Print the index of the day with the most views, counting from 0.
Example 1
Input
6 120 450 900 610 300 80
Output
2
The views rise to 900 at index 2 and then fall.
Example 2
Input
3 1 5 2
Output
1
The smallest mountain.
Try the problem first. Open one hint at a time.
Look at the middle day and the day right after it.
If the next day has more views, you are still climbing, so the peak is to the right.
If the next day has fewer views, you are on the way down or at the top, so the peak is the middle or to its left.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor