Baseline Binary Trees · Traversals O(n) · O(n)
A demolition contractor surveys a building shaped like a binary tree of structural bays. Safety law forbids logging a bay for teardown until every bay beneath it — the whole left wing and then the whole right wing — has already been inspected. Only after both wings are cleared does the crew sign off the bay itself. The signed-off sequence is what the permit office receives.
Input: The root of a binary tree given as a level-order array where null marks a missing child.
Output: Return an array of node values in postorder: visit the left subtree, then the right subtree, then the node.
1 <= number of nodes <= 10^5-100 <= node value <= 100Input: {"tree":[1,2,3,4,5,null,6]}
Output: [4,5,2,6,3,1]
Left subtree finishes as 4,5,2; right subtree as 6,3; the root lands last.
Input: {"tree":[7]}
Output: [7]
A single node has no children, so it is visited first and last.