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.

HardTechnical
54 practiced
Explain divide-and-conquer DP optimization (also called monotone or divide-and-conquer optimization) that can reduce DP from O(n^2) to O(n log n) or O(n). State the prerequisites (monotone argmin or quadrangle inequality), derive how to restrict search ranges when computing dp[l..r] from previous opt ranges, and provide a code sketch that demonstrates the technique and its complexity analysis.
EasyTechnical
95 practiced
Implement lower_bound in C++: given a sorted vector<int> arr and int target, return the lowest index in [0,n] where target can be inserted to keep arr sorted. Examples: arr=[1,3,3,5], target=3 -> 1; target=4 -> 3. Provide iterative code using binary search, ensure O(log n) time, and discuss relationship to std::lower_bound and off-by-one guarantees.
MediumTechnical
60 practiced
Describe the divide-and-conquer approach to count inversions in an array by modifying merge sort. Provide pseudocode that returns a 64-bit inversion count and derive the recurrence T(n)=2T(n/2)+Θ(n). Solve the recurrence to Θ(n log n) and explain how to handle equal elements so you don't overcount inversions.
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
57 practiced
Given a huge read-only sorted dataset on disk (too large for RAM), design and provide pseudocode for an external-memory binary search that minimizes disk seeks and memory footprint. Take block size B into account, explain how to align probes to block boundaries, describe prefetching and caching policies for block reads, and analyze I/O complexity in terms of number of block reads and seeks.

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.