Loading...
Loading...
A shopping app shows the price of a phone for n days. The prices were in increasing order, but the app rotated the list: it moved some days from the front to the back. For example, 10 20 30 40 50 may become 40 50 10 20 30. The list may also be left as it was.
All prices are different. Print the lowest price.
Example 1
Input
5 40 50 10 20 30
Output
10
The list was rotated after 50, so the lowest price 10 is in the middle.
Example 2
Input
4 12 18 25 31
Output
12
The list was not rotated, so the lowest price is the first one.
Try the problem first. Open one hint at a time.
Compare the middle price with the last price of the current range.
If the middle price is larger than the last one, the drop happens to the right of the middle.
Otherwise the part from the middle to the end is sorted, so the lowest price is the middle or to its left.
Keep hi = mid in that second case, because the middle itself may be the lowest price.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor