A gauge logs n distinct meter readings that were originally listed in strictly increasing order, then the list was cyclically rotated by some unknown amount (possibly zero). Recover and report the single smallest reading.
Line 1: an integer n.
Line 2: n space-separated integers: a rotation of a strictly increasing sequence (all values distinct).
A single integer: the minimum reading.
Example 1
Input
5 4 5 1 2 3
Expected
1
Explanation
The underlying increasing sequence is 1 2 3 4 5 rotated so it begins at 4; its minimum is 1.
Example 2
Input
3 1 2 3
Expected
1
Explanation
No rotation was applied, so the minimum is simply the first value, 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 →