Remove an Expired Session Key From a BST Index

Last updated: November 29, 2026

Quick Overview

Given the root of a BST of session keys and a key, delete the node with that key (if present) and return the new root while keeping BST order.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given the root of a BST of session keys and a key, delete the node with that key (if present) and return the new root while keeping BST order.

BST deletion shows up in Meta technical screens to check careful pointer handling. The interviewer looks for the three cases (leaf, one child, two children) and the successor-copy trick, plus correct handling when the root itself is deleted.

What the Interviewer Expects
  • Search for the key using BST ordering
  • Handle zero and one child by splicing
  • For two children, copy the in-order successor and delete it from the right subtree
  • Return the new root
  • State O(h) complexity
Key Topics to Cover
BST
deletion
in-order successor
recursion
pointer manipulation
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Delete without copying values (relink nodes) because values are large payloads.
  • How would you keep the tree balanced after deletes?
  • Delete all keys within a range.
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: BST root, integer key.
  • Output: root of the BST after removing the node with that key, or unchanged if absent.
  • Keys are unique....
High-Level Design

Recurse down using comparisons until the key is found. Then:

  1. No left child: replace the node with its right subtree (covers leaves too).
  2. No right child: replace it with its left subtree...

Submit Your Answer
Markdown supported