InterviewLegend

Trees & Heaps

Alex Chen24 min readUpdated 387 real interview reports

Trees and heaps at Apple lean toward the clean classics rather than puzzle-box twists. The questions that recur have a tidy correct answer and a small number of edge cases. Those cases separate a working solution from one that crashes on a single node or a skewed chain. Three carry most of this slice: a Premium question, a Premium question of two nodes, and the streaming median. The first two are tree recursion. The third is the two-heap pattern, and it is the one that tests whether you can keep an invariant true across a long sequence of operations.

Two shapes cover all three. When a node needs a value from each of its subtrees, you are in a bottom-up recursion. Solve both children first, combine what they report, return one thing to the parent, and let the real answer accumulate in a variable off to the side. The streaming median runs on two heaps kept balanced against each other, which parks the middle of the data at the top of one heap or the other. Name the shape first. After that the work is bookkeeping, getting the base cases and the balance right.

What's inside
  • 6 problems, worked step by step
  • 1 diagram
  • about 24 min

Premium lessonApple interview guide

These took digging.

What candidates walked out with, from 20,000+ reports, forum threads behind logins and write-ups in Chinese. Then solved step by step.

100 companies. Checked every month.

Unlock all 100 companies

$49 a year · less than $1 a week · Cancel anytime

Had your Apple interview?Tell us what they asked. Reviewed before it goes in, never with your name.
Apple interview guide

Know what Apple asks before you walk in.

22 coding · 4 system design · 30 behavioral questions

Get Premium$49 a year · Cancel anytime
Or start freeNo card.

Get their questions first.

InterviewLegend is independent and not affiliated with or endorsed by any company it covers.