Question 1
Alice has some cards with numbers written on them. She arranges the cards in decreasing order, and lays them out face down in sequence on a table. she challenges Bob to pick out the card containging a given number by turning over as few cards as possible. Write a function to help Bob locate the card.
cards= [13, 11, 10, 7, 4, 3,8, 9, 24]
query= 24
output = 4
Linear search
Q 2
how many time the sorted list is rotated:
Linear search
{'input': {'nums': [4, 5, 8, 9, 10]}, 'output': 0} output: 0
{'input': {'nums': [4, 5, 6, 7, 8, 1, 2, 3]}, 'output': 5} output: 5
{'input': {'nums': [7, 3, 5]}, 'output': 1} output: 1
{'input': {'nums': [3, 5, 7, 8, 9, 10]}, 'output': 5} output: 0
Wall time: 999 µs
{'input': {'nums': [4, 5, 8, 9, 10]}, 'output': 0} output: 0
{'input': {'nums': [4, 5, 6, 7, 8, 1, 2, 3]}, 'output': 5} output: 5
{'input': {'nums': [7, 3, 5]}, 'output': 1} output: 1
{'input': {'nums': [3, 5, 7, 8, 9, 10]}, 'output': 5} output: 0
Wall time: 0 ns