Binary Search

Find the index of an element in a sorted array using binary search with O(log n) time complexity.

Code

Algorithms
import bisect
i = bisect.bisect_left(arr, target)
return i if i < len(arr) and arr[i] == target else -1

Parameters

Sorted array

Element to find

Server

More Python Snippets