Your question is Mirror Image of a Tree. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
AMD firmware and driver tools may represent device relationships as binary trees. Given the root of a binary tree, transform it into its mirror image in place by swapping the left and right child of every node, then return the root.
Implement mirror_tree(root), where root is either None or a TreeNode with fields val, left, and right. Modify the existing nodes rather than creating replacement nodes. The function returns the same root reference, or None for an empty tree.
For examples and test cases, trees are serialized in level-order. null represents a missing child, and unnecessary trailing null values are omitted.
def mirror_tree(root):