Binary Search

Binary search is an efficient algorithm for finding a target value in a sorted array or collection by repeatedly dividing the search space in half, achieving a time complexity of O(log n). Below are some interview-ready binary search questions covering common patterns.

Filter by difficulty:
Basic Binary Search
Search for a target value in a sorted array Easy
Find the first and last position of a target in a sorted array Medium
Find the smallest element greater than or equal to a given number (ceiling) Easy
Find the largest element smaller than or equal to a given number (floor) Easy
Rotated Sorted Array
Find the minimum element in a rotated sorted array Medium
Find the maximum element in a rotated sorted array Medium
Search for a target value in a rotated sorted array Medium
Two Sorted Arrays
Find the kᵗʰ smallest element using binary search on partitions Hard
Find the median of two sorted arrays in logarithmic time Hard
Binary Search on Matrix
Search a value in a fully sorted 2D matrix Medium
Peak Element
Find any peak element greater than its neighbors Medium