Loading...
Loading...
Loading...
A sorted list of distinct product codes is given, followed by some queries. For each query print its position (counting from 0) in the list, or -1 when it is not there. The starter holds a program with a bug. Find it and fix it.
Example
Input
5 10 20 30 40 50 3 30 35 10
Output
2 -1 0
Try the problem first. Open one hint at a time.
Halve the search range each time, as binary search does.
A range with one item left must still be checked.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor