โ† Trees, Graphs & DP
#2 most askedVery commonEasyTree DFS

Invert Binary Tree

New to Tree DFS? Learn it from scratch first
Trees & Binary Search Trees โ†’
๐Ÿข Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.
I was asked this

Mirror a binary tree (swap every node's left and right children) and return the root.

[4, 2, 7, 1, 3, 6, 9] โ†’ [4, 7, 2, 9, 6, 3, 1]

๐Ÿงช Practice

Write your solution, then press Run tests. Explain your approach out loud as you go.

Python
def invert_tree(root):
    pass

Output appears here. Press Run or Ctrl/โŒ˜ + Enter.

Try it first. Struggling for a few minutes is how it sticks.