Given a binary search tree, remove every node whose key is smaller than a specified value. When a node is removed, its subtrees must be removed as well.
root: the root of the binary search treethreshold: the integer value used for pruningInput
root = [3,0,4,null,2,null,null,1], threshold = 2
Output
[3, null, 4, 3]
root = [3,0, 4, null, 2, null, null, 1] threshold = 2
[3,null, 4, 3]
Original binary search tree. Threshold = 2: we must remove every node with key < 2 and its subtrees.
This output represents the tree remaining after nodes with keys below 2 and their subtrees are removed.
root = [3,0, 4, null, 2, null, null, 1] threshold = 2
[3,null, 4, 3]
Original binary search tree. Threshold = 2: we must remove every node with key < 2 and its subtrees.