Invert a binary tree by swapping the left and right children of every node.
Input: root = [4,2,7,1,3,6,9]
Output: [4,7,2,9,6,3,1]
Topics: trees, recursion
Asked by: Amazon, Google, Meta, Microsoft, Apple
Time complexity: O(n). Space complexity: O(h).