Invert Binary Tree

TopicDifficultyCompanies
Binary Tree
MEDIUM
Amazon
Google

Given a binary tree, write a program to invert the binary tree and return it.

Example

Input:
5
/ \
2 8
/ \ / \
1 4 6 9
Output:
5
/ \
8 2
/ \ / \
9 6 4 1

Code Editor

Practice and Learn

Best way to learn is through solving real problems. Practice this problem in this code editor.