Standard Bar Binary Search Trees · Practice Problems O(h) · O(h)
A mail-sorting hub must decommission one station without breaking the smaller-left, larger-right flow. A retiring station with no lines simply vanishes; with one line, its single branch takes over the slot; with two lines, the hub promotes the smallest station from the retiring one's right wing into its place, then quietly repeats the retirement on that promoted station's old spot.
Input: A binary search tree as a level-order array (null marks a missing child) and an integer key — the node value to remove.
Output: Return the tree after deletion, serialized as a level-order array with trailing nulls trimmed.
1 <= number of nodes <= 10^5-10^9 <= node value, key <= 10^9All node values are uniqueInput: {"tree":[5,3,6,2,4,null,7],"key":3}
Output: [5,4,6,2,null,null,7]
3's slot is filled by 4, the smallest value in its right wing, which is then removed from below.
Input: {"tree":[5,3,6],"key":3}
Output: [5,null,6]
A leaf vanishes outright, leaving an empty branch.