InterviewLegend

Trees

Alex Chen24 min readUpdated 557 real interview reports

Trees are a Google staple, and almost every tree question is recursion in disguise. The hard part isn't the recursion itself, it's deciding what each node needs: an answer assembled from its children, or context handed down from its ancestors. Get that right and the code is short.

That one decision splits nearly all tree problems into two shapes. In the first, you solve the subtrees first and combine their results on the way back up. In the second, you carry information down as you descend and act on it at each node. Name which one you're in, and most tree interviews come unstuck.

What's inside
  • 3 problems, worked step by step
  • 6 diagrams
  • about 24 min

Premium lessonGoogle 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 Google interview?Tell us what they asked. Reviewed before it goes in, never with your name.
Google interview guide

Know what Google asks before you walk in.

34 coding · 7 system design · 47 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.