InterviewStack.io LogoInterviewStack.io

Binary Search and Efficient Searching Questions

Understanding binary search algorithm, when it's applicable, and ability to implement correctly. Includes recognizing problems that can be solved with binary search on arrays or values.

MediumTechnical
99 practiced
Given a rotated sorted array, compute how many positions it has been rotated (i.e., index of the minimum element) in O(log n) time. Example: [6,7,0,1,2,4,5] -> 2. Implement and explain the invariants used to detect the pivot.
HardTechnical
100 practiced
You must run a binary search where evaluating the predicate is very expensive (e.g., runs a heavy DB query). Propose strategies to reduce total evaluation cost: caching, memoization, approximation, narrowing bounds cheaply, parallel checks, or early termination. Provide a concrete example and estimate cost improvements.
EasyTechnical
99 practiced
Before using binary search, a caller wants to ensure the array is sorted. Describe an efficient approach to verify sortedness for a single check and discuss trade-offs for one-time versus repeated searches. If the array is not sorted and you must support many queries, what strategies would you recommend?
EasyTechnical
99 practiced
Explain the difference between lower_bound and upper_bound on a sorted array. Define each precisely (in terms of first index >= target and first index > target), show how to compute the count of a value using them, and give a short example: nums=[1,2,2,2,3], target=2.
MediumTechnical
72 practiced
You have time-stamped monitoring metric logs that are monotonic for a given window. Design an algorithm to find the first timestamp when the metric exceeds a threshold using binary search across daily partitions and a secondary binary search within a day. Discuss trade-offs when logs are partitioned across multiple storage tiers.

Unlock Full Question Bank

Get access to hundreds of Binary Search and Efficient Searching interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.