← Apple Interview Insights

Apple·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Apple SWE interview with a classic algorithms problem. Not much to report beyond the question itself, but it's the kind of thing that separates people who've drilled it from people who haven't.

Questions Asked (1)

Q1

Given two sorted arrays, find their median.

Algorithms & Data Structures
Author's notes

The naive merge-and-find approach works but they're clearly waiting for the binary search solution.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem constraints (array sizes, sorted order, definition of median for even total length). Then present a binary search solution that partitions the two arrays into left and right halves of equal size, achieving O(log(min(m,n))) time. Walk through edge cases and compare with the simpler O(m+n) merge approach to show trade-offs.

Pro tip: At Apple, interviewers value clean, efficient code and clear communication. Before coding, explicitly state the time and space complexity of your approach and how it handles edge cases like empty arrays or one array being much larger than the other.

1. Clarify the problem

Ask about array sizes, whether they can be empty, and how to define the median for even total length (average of two middle elements). Confirm that the arrays are sorted in ascending order.

2. Discuss naive and optimal approaches

Mention the O(m+n) merge approach as a baseline, then propose the binary search on the smaller array for O(log(min(m,n))) time. Explain why binary search works: we partition both arrays such that all elements on the left are ≤ all elements on the right.

3. Derive the binary search conditions

Define partition indices i and j for the two arrays. Ensure i + j = (m + n + 1) / 2. The correct partition satisfies: leftMax1 ≤ rightMin2 and leftMax2 ≤ rightMin1. Adjust the search range based on these conditions.

4. Handle edge cases and compute median

Handle cases where a partition is at the boundary (i=0 or i=m) by using sentinel values like -∞ and +∞. Compute the median: if total length is odd, it's max(leftMax1, leftMax2); if even, it's the average of max(leftMax1, leftMax2) and min(rightMin1, rightMin2).

5. Analyze complexity and test

State that time complexity is O(log(min(m,n))) and space is O(1). Walk through a few examples, including edge cases like one empty array, to verify correctness.

Key Points to Mention

  • Binary search on the smaller array to achieve O(log(min(m,n))) time complexity
  • Partitioning logic: ensuring left half elements are ≤ right half elements
  • Handling even vs. odd total length for median calculation
  • Edge cases: empty arrays, one array significantly larger, all elements of one array smaller
  • Comparison with the O(m+n) merge approach and why binary search is better
  • Space complexity O(1) and in-place nature of the algorithm

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.