Searching · stretch
Minimum of a rotated list
A sorted list of different numbers was rotated: [4, 5, 6, 1, 2, 3]. Write rotated_min(items) returning the smallest number, looking at far fewer than all of them.
Compare the middle with the last item: if the middle is bigger, the drop is to its right.
- right answers
- arguments left as they should be
- fast enough at scale
- without min, sorted, sort
Run adds print(rotated_min([4, 5, 6, 1, 2, 3])) after your code, to try it.
Stuck on the idea rather than the code? The Binary search, the useful kind lesson walks through it.