root of a perfect binary tree: every internal node has exactly two children and all leaves sit at the same depth. The root has depth 0, its children depth 1, and so on.
On every odd depth, reverse the node values: if that level reads a, b, c, d from left to right, it must become d, c, b, a. The shape of the tree stays the same. Return the root.root=tree_node([1, 6, 9]) → [1, 9, 6]
At depth 1 the values 6 and 9 swap places.
root=tree_node([4, 2, 8, 10, 20, 30, 40]) → [4, 8, 2, 10, 20, 30, 40]
Depth 1 is reversed into 8, 2. Depth 2 is even and stays 10, 20, 30, 40.
root=tree_node([7]) → [7]
There are no odd depths, so the tree is unchanged.
root=tree_node([1, 6, 9])
[1, 9, 6]
Run checks the first 3 tests in your browser. Submit checks all 13 tests on the server, hidden ones included.