DSA interview question
The leaderboard BST must also support removing a score while staying a valid BST. Deletion has three cases:
Example: BST [5, 3, 6, 2, 4, null, 7], delete 3 → [5, 4, 6, 2, null, null, 7].
TreeNode* deleteNode(TreeNode* root, int key); // returns the new root; no-op if key is absent
Input (tree, key) | Output (level order) | Explanation |
|---|---|---|
([5, 3, 6, 2, 4, null, 7], 3) | [5, 4, 6, 2, null, null, 7] | Two children: replaced by successor 4 |
([5, 3, 6, 2, 4, null, 7], 5) | [6, 3, 7, 2, 4] | The root is replaced by 6 |
([5, 3, 6, 2, 4, null, 7], 0) | [5, 3, 6, 2, 4, null, 7] | Key absent |
([1], 1) | [] | The last node |
([], 0) | [] |
(Confirm: keys are distinct; any valid resulting BST is accepted, and the successor-replacement result is shown.)
On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.
Book a free mock interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in