Trees interview questions

Binary tree recursion, traversal orders, level-by-level walks, binary search tree rules and the questions built on them, all with one small Node class.

5 quick facts

– interview-ready · 16 questions in this topic

– of 16 tried

Saved on this device. Interview-ready means you got it right on two different days. Guesses and hints count for less.

Questions

  1. How trees are written on these pagesPredict
  2. How deep is the deepest branch?Pick the fix
  3. Is this a valid binary search tree?Pick the fix
  4. List a tree's values row by rowFill the blank
  5. Are two trees identical?Predict
  6. Does a tree mirror itself?Pick the fix
  7. Swap every node's left and right childrenPredict
  8. Longest path between any two nodesPick the fix
  1. Is every node's left and right height within one?Predict
  2. What you see from the right of a treePick the fix
  3. The k-th smallest value in a search treeOrder the steps
  4. Closest shared ancestor in a search treePredict
  5. Does a root-to-leaf route add up to a target?Pick the fix
  6. Pre-order, in-order, post-order and level orderPredict
  7. Why search trees need to stay balancedPredict
  8. Recursion depth and when to walk a tree iterativelyPredict

Practise this topic

Flashcards · 26

Flip, then say if you knew it. Needs JavaScript; every answer is also on its question page.

Quick quiz · 16 questions

One exercise per question, checked as you go. Needs JavaScript.

Mock interview · 3 sets

Timed, out loud, then tick what you covered. Needs JavaScript.

Quick facts

Recall the answer first, then tap Show to check.

Sources: Topic outline informed by the Tech Interview Handbook by Yangshun Tay and the NeetCode 150 pattern grouping by neetcode-gh, both MIT licensed. Every problem, solution and explanation is written by Best Latest Apps. Credits and license