Editor

Tree problems in Python

Walk, measure and search hierarchies in Python, on tree problems with tests that check your code.

Beginner

  1. 52. Maximum Depth of a TreeHow many levels tall is this tree?45 XP8 min
  2. 215. Count the LeavesThe quiet ends of a busy comment thread30 XP5 min

Intermediate

  1. 54. Mirror a TreeFlip a tree as if it stood in front of a mirror55 XP8 min
  2. 66. Root-to-Leaf Path SumIs there a way down the tree that adds up exactly?60 XP10 min
  3. 70. Level Order TraversalRead a tree one floor at a time65 XP10 min
  4. 95. Right Side ViewWhat do you see standing to the right of a tree?75 XP12 min
  5. 98. Folder SizesHow much space does each folder really take up?80 XP15 min
  6. 110. Valid Binary Search TreeIs this search tree really in order?85 XP14 min
  7. 290. Symmetric TreeWould this tree look the same in a mirror?65 XP12 min
  8. 297. Balanced Binary TreeDoes any branch of this tree grow too long?70 XP13 min
  9. 308. Root-to-Leaf PathsEvery way down a tree, written out in full70 XP12 min

Advanced

  1. 127. Diameter of a TreeThe longest walk between any two nodes of a tree120 XP20 min
  2. 138. Lowest Common AncestorWhere do the paths to two nodes split apart?125 XP20 min
  3. 166. Rebuild a Tree from TraversalsRecover a whole tree from two lists of its values160 XP30 min
  4. 363. Vertical Order of a TreeRead a tree column by column, from left to right125 XP25 min
  5. 402. Where to Put the ServerWhere should the server sit so that no office is too far away?145 XP30 min

Expert

  1. 172. Save and Restore a TreePack a tree into text and unpack it without losing a branch195 XP35 min
  2. 180. Maximum Path SumThe richest route through a tree, starting and ending anywhere215 XP35 min
  3. 441. Cameras on a TreeWatch every corner of a tree with as few cameras as possible220 XP40 min
  4. 448. Same Shape TreesTwo family trees: the same shape underneath?220 XP45 min
  5. 472. Sum of Distances in a TreeHow far is every village from all the others?240 XP45 min

Other topics

Or see every challenge, with study plans, today's challenge and duels.