Binary Search

Easy
sorting Google Amazon Microsoft

Implement binary search to find the index of a target value in a sorted array. Return -1 if not found.

Example

binary_search([1, 3, 5, 7, 9, 11], 7)
# => 3
binary_search([1, 3, 5, 7, 9, 11], 4)
# => -1

Test Cases

Python Editor

Output

Click "Run" to see results...