Good morning! Here's our prompt for today.
We're given an array of integers that looks like the following:
1[0, 1, 2, 3, 4, 5, 6, 7, 8]
Let's imagine we're an assembly line and we decide to shift some workers around.
Say we take our array, and rotate it at a random pivot so that the section after the pivot comes before. Let's put our pivot between 5
and 6
:
1[6, 7, 8, 0, 1, 2, 3, 4, 5]
See how it shifts?

Can you find the smallest element in O(log n)
time? Assume that there are no repeat numbers.
Here are some other examples: given [4, 5, 1, 2, 3]
, we'd get 1
.
In the event that there's a missing number in the sequence like [5, 6, 7, 0, 1, 2, 3]
(where 4
isn't present), the output would still be 0
.
Constraints
- Length of the array <=
100000
- The values in the array will be between
-1000000000
and1000000000
- Expected time complexity :
O(log n)
- Expected space complexity :
O(1)
Try to solve this here or in Interactive Mode.
How do I practice this challenge?
xxxxxxxxxx
def get_minimum(nums):
# fill in
return nums
​
​
import unittest
​
​
class Test(unittest.TestCase):
def test_1(self):
assert get_minimum([6, 7, 8, 0, 1, 2, 3, 4, 5]) == 0
print("PASSED: `get_minimum([6, 7, 8, 0, 1, 2, 3, 4, 5])` should equal `0`")
​
def test_2(self):
assert get_minimum([6, 7, 8, 9, 10, 3, 4, 5]) == 3
print("PASSED: `get_minimum([6, 7, 8, 9, 10, 3, 4, 5])` should equal `3`")
​
​
if __name__ == "__main__":
unittest.main(verbosity=2)
print("Nice job, 2/2 tests passed!")
​
We'll now take you through what you need to know.
How do I use this guide?
Access all course materials today
The rest of this tutorial's contents are only available for premium members. Please explore your options at the link below.