DiffPush Tier Binary Trees · Hard O(n) · O(1)
A distribution hub is switching from a tree of branch conveyors to one straight express lane. Every station must survive the re-rack, and the order along the new lane must be exactly the hub-first walk of the old tree — each station's left spur is dismantled and spliced into the lane ahead of its right spur, all rewiring done with the existing stations and zero spare parts.
Input: A binary tree as a level-order array (null marks a missing child).
Output: Return the station values along the flattened lane — the preorder sequence after rewiring every left pointer to null and every right pointer to the next station.
1 <= number of nodes <= 10^5-10^4 <= node value <= 10^4Expected extra space: O(1) — flatten in placeInput: {"tree":[1,2,5,3,4,null,6]}
Output: [1,2,3,4,5,6]
The preorder walk 1-2-3-4-5-6 becomes the single right-leaning lane.
Input: {"tree":[1,null,2,3]}
Output: [1,2,3]
The left spur of node 2 splices in before nothing, so the lane keeps 1-2-3.