Easy · Trees

Flip tree

Given the root of a binary tree, mirror it in place by swapping the left and right children of every node, and return its root.

Examples

Example 1

[1,2,3,4,5,6,7]

Output: [1,3,2,7,6,5,4]

Example 2

[4,2,7,1,3,6,9]

Output: [4,7,2,9,6,3,1]

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Trees problems