LearnPy Hub
← Functions problems
Hard

Binary Search

Write search(sorted_list, x) that returns the index of x using binary search, or -1. Read a sorted line of integers and x.

Input

Sorted integers, then x.

Output

An index or -1.

Sample 1

Input
1 3 5 7 9
7
Output
3

Sample 2

Input
1 3 5 7 9
4
Output
-1
solution.py
Output appears here
Binary Search · Python practice problem · LearnPy Hub