InterviewStack.io LogoInterviewStack.io

Binary Search and Divide And Conquer Questions

Covers binary search algorithms and the divide and conquer problem solving paradigm. Candidates should know the classic binary search on sorted arrays, off by one and loop invariant considerations, iterative and recursive implementations, and common variants such as searching in rotated sorted arrays, finding first or last occurrence, and search in ranges. Include advanced variants like search on monotonic functions and binary search on answer. Cover divide and conquer design patterns including problem partitioning, conquering subproblems, and combining results with attention to recurrence relations and time complexity analysis. Emphasize edge cases, correctness proofs, complexity trade offs in time and space, and practical considerations for constrained or real time systems such as memory partitioning and latency constraints. Questioners may probe algorithm invariants, complexity derivations, and application of divide and conquer to design efficient solutions.

MediumTechnical
53 practiced
You have a read-only sorted array-like API get(i) that returns element at index i or +infinity if i is out-of-bounds. Implement search(target) minimizing calls to get(). Use exponential backoff (1,2,4,8...) to find an upper bound then binary search within bounds. Provide Python code outline and analyze number of get() calls as O(log p) where p is position index of the target.
HardTechnical
61 practiced
Design a divide-and-conquer algorithm for the maximum subarray (maximum contiguous sum). Provide pseudocode for divide, conquer, and combine steps (left max, right max, crossing max), prove correctness, solve the recurrence T(n)=2T(n/2)+Θ(n) to get Θ(n log n), and compare to Kadane's O(n) algorithm. Discuss when divide-and-conquer could be preferred (e.g., parallelism).
HardTechnical
53 practiced
Solve the recurrence T(n)=T(n-1)+T(n/2)+n using recursion tree or substitution to obtain asymptotic bounds. Explain why standard master theorem does not directly apply and provide tight upper and lower bounds in Theta notation, justifying each step of your derivation.
HardSystem Design
45 practiced
Design a low-latency (<10ms) distributed search for monotonically increasing sensor data streams where each node holds a segment and memory per node is limited to 256MB. Describe how to partition segments, use divide-and-conquer to parallelize queries across nodes, keep memory and indexing within limits, handle stale or partially replicated data, ensure consistency and failover, and meet SLA while minimizing network overhead.
HardTechnical
58 practiced
You observe a production binary search intermittently returning incorrect indices. Logs hint at integer overflow and concurrent modifications to the underlying array. Outline a debugging and remediation plan: how to reproduce, what instrumentation/logging to add, immediate hotfix options, long-term fixes (immutability, snapshots), tests to add, and monitoring changes to detect regression.

Unlock Full Question Bank

Get access to hundreds of Binary Search and Divide And Conquer interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.