Find Minimum in Rotated Sorted Array
Real-world version: Wrapped Buoy Low OffsetThe statement here is our own: the same inputs, outputs and technique.
A weather buoy stores calibration offsets in a ring buffer. The offsets were written into the ring in strictly increasing order, one per slot, and afterwards the buffer's start marker was slid forward by some number of slots. Dumping the ring from the marker therefore hands you the increasing run cut at one slot, with the piece before the cut moved behind the piece after it. The marker may also have been slid all the way around the ring, and then the dump comes out plainly increasing.
Offsets can be below freezing, so negative values are ordinary. No two offsets are equal.
Given the dump offsets, report the smallest offset it holds. Your routine must settle the answer in logarithmic time, so reading every slot is off the table.
Examples
Example 1
- Input
- offsets = [-4, -1, 3, -9, -7]
- Output
- -9
The increasing run was -9, -7, -4, -1, 3; the cut fell after -1, so the run restarts at slot 3 and the low offset sits there.
Example 2
- Input
- offsets = [2, 7, 9]
- Output
- 2
The marker travelled the full ring, so the dump is still increasing and the low offset is the first slot.
Example 3
- Input
- offsets = [5000, -5000]
- Output
- -5000
Two slots with the cut between them, so the second slot restarts the run.
Constraints
- n == offsets.length
- 1 <= n <= 5000
- -5000 <= offsets[i] <= 5000
- No two offsets are equal
- offsets is a strictly increasing run whose start marker was slid forward between 1 and n slots
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def lowest_offset(offsets: list[int]) -> int:public int lowestOffset(int[] offsets)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's