Binary Search

00:00
EasyArrayBinary SearchDivide & Conquer
TCSWiproAmazon

Find target in sorted array. Return index if found, -1 if not. Must be O(log n).

Examples

Input → [-1,0,3,5,9,12], target=9
Output → 4
Input → [-1,0,3,5,9,12], target=2
Output → -1
Input → [1], target=1
Output → 0
Input → [1,3], target=3
Output → 1