Loading content...
Given the root node of a binary tree, return the bottom-up level order traversal of the node values. This means you should traverse the tree level by level, but present the levels in reverse order—starting from the deepest (leaf) level and working upward to the root.
Within each level, nodes should be listed from left to right as they appear in the tree. If the tree is empty (i.e., the root is null), return an empty list.
Understanding the Traversal:
Tree Representation: The binary tree is provided in level-order format as an array where:
null values represent absent nodesroot = [3,9,20,null,null,15,7][[15,7],[9,20],[3]]The tree has three levels. Level 0 (root): [3]. Level 1: [9, 20]. Level 2 (deepest): [15, 7]. The bottom-up traversal reverses this order, presenting the deepest level first: [[15,7],[9,20],[3]].
root = [1][[1]]The tree contains only the root node with value 1. Since there is only one level, the result is [[1]].
root = [][]An empty tree (null root) has no nodes to traverse, so the result is an empty list.
Constraints