LeetEye LeetEye
Cheat Sheet

Trees Cheat Sheet

Quick reference for coding interviews. Bookmark this page!

What is Trees?

Traverse and manipulate hierarchical data structures.

Trigger Words

When you see these in a problem, think Trees:

invert binary tree trees maximum depth of binary tree validate binary search tree lowest common ancestor of a binary search tree binary tree level order traversal binary tree right side view serialize and deserialize binary tree binary tree maximum path sum

Template Code

def invertTree(root: TreeNode) -> TreeNode:
    if not root:
        return None
    
    # Swap left and right children
    root.left, root.right = root.right, root.left
    
    # Recursively invert subtrees
    invertTree(root.left)
    invertTree(root.right)
    
    return root

Complexity

Typical Time O(n)
Typical Space O(h)

Common Variations

  • Basic Trees
  • Trees with constraints
  • Optimized Trees

Practice Problems

See all Trees problems →

Practice Trees

Learn to recognize patterns instantly with interactive MCQs.

Download LeetEye Free
Practice in LeetEye