Trains the technique from
LeetCode 450Delete Node in a BSTThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A depot keeps its locker codes in a binary search tree: every code in a node's left subtree is smaller than that node's code and every code in its right subtree is larger, and no code is stored twice.
The tree arrives as index, a level-by-level listing. index[0] is the root. After that, every node already listed contributes two entries in turn, its left child then its right child, with null where that child is missing. A null contributes nothing further, and null entries at the very end are left off. An empty listing means the tree is empty.
The locker with code code is being retired. Take its node out of the tree and return the resulting tree in the same level-by-level listing, again with trailing null entries left off. When no node holds code, hand back the tree as it arrived.
So that exactly one listing is correct, removal follows these rules:
What comes back is still a binary search tree.
Example 1
The root holds 50 and has children on both sides. The smallest code in its right subtree is 60, so the root takes on 60, and the node that held 60 has no children of its own and is dropped from under 70.
Example 2
The node holding 20 has no children, so it is dropped and every other node stays where it was.
Example 3
No node holds 99, so the listing comes back exactly as it arrived.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def retire_locker(index: list[int | None], code: int) -> list[int | None]:public Integer[] retireLocker(Integer[] index, int code)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.