Sorting and Searching Algorithms Questions

Comparison and non-comparison sorts (quicksort, mergesort, heapsort, counting/radix), their stability and complexity, and binary search with its many variants. Covers divide-and-conquer reasoning, searching in rotated or implicit spaces, and choosing an algorithm from input constraints. A staple of both fundamentals screens and optimization discussions.

HardTechnical
67 practiced

Implement an O(log(min(m,n))) algorithm in Python to find the median of two sorted arrays of lengths m and n. Signature: def find_median_sorted_arrays(a: List[int], b: List[int]) -> float. Explain handling of even/odd combined lengths and provide correctness reasoning for the partitioning approach.

MediumSystem Design
67 practiced

You have a 1TB log file stored on disk but only 1GB of RAM in your backend worker. Design an algorithm and step-by-step plan to sort the file by timestamp so it can be consumed by downstream analytics. Include chunking strategy, disk I/O considerations, parallelism, and how to perform the final merge with limited memory.

EasyTechnical
45 practiced

Implement a function in Python that merges two sorted arrays and returns a single sorted array. Signature: def merge_sorted(a: List[int], b: List[int]) -> List[int]. Discuss an in-place alternative if you are given sufficient extra capacity at the end of one array (e.g., a has len(a)+len(b) capacity).

HardTechnical
64 practiced

Implement the deterministic median-of-medians selection algorithm (worst-case linear-time selection) in Java. Signature: public static int medianOfMediansSelect(int[] arr, int k). Explain why choosing medians of groups yields O(n) worst-case time and provide complexity proof sketch.

MediumTechnical
53 practiced

Given a sorted array (ascending) of integers that may contain duplicates, implement a Python function that returns all unique pairs (value pairs, not indices) whose sum equals target. Signature: def unique_pairs(nums: List[int], target: int) -> List[Tuple[int,int]]. Aim for O(n) time and O(1) extra space (excluding output).

Unlock Full Question Bank

Get access to all 33 Sorting and Searching Algorithms interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.