Roadmap › Stage 6: Trees › Pattern 29 of 53
DSA pattern guide

Tree — LCA & Construction

Lowest common ancestor, build a tree from traversals, serialize.

Stage 6 · Trees7 problems1 Easy · 4 Medium · 2 Hard

Use it when

Lowest common ancestor, build a tree from traversals, serialize.

Key idea

LCA: the node where p and q split into different subtrees. Construction: the preorder root splits the inorder array.

Practice problems, in order

  1. Invert Binary TreeEasy
  2. Lowest Common Ancestor of Binary TreeMedium
  3. Flatten Binary Tree to Linked ListMedium
  4. Construct Binary Tree from Preorder & InorderMedium
  5. Construct Binary Tree from Inorder & PostorderMedium
  6. Kth Ancestor of a Tree NodeHard
  7. Serialize and Deserialize Binary TreeHard

How to practise this pattern

  1. Read the problem and look for the signal above before writing any code.
  2. Say the brute force out loud, with its time complexity, then ask what work it repeats.
  3. Apply the key idea and write the optimised version yourself.
  4. If you're stuck for more than 10 minutes, take one small hint, not the full solution.
  5. Move to the next problem only when you can explain why this pattern fits.

Stuck on one of these?

The AlgoSolveo extension (free, launching soon) sits beside the LeetCode problem and gives the smallest hint that gets you moving, never the full answer. Solved problems tick off on your roadmap.

Join the extension waitlistTrack it on the roadmap
← Previous patternTree — BFS / Level OrderNext pattern →Binary Search Tree