← Microsoft Interview Insights

Microsoft·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Microsoft SWE interview with a BST deletion problem. Pretty standard coding round, nothing too wild, but the edge cases will get you if you're not careful.

Questions Asked (1)

Q1

Given a binary search tree, write a function to delete a node with a given key and return the updated tree.

Algorithms & Data Structures
Author's notes

The basic delete is fine but I fumbled on the case where the node has two children.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by explaining the recursive search for the node, then handle the three deletion cases: leaf, one child, and two children. For the two-children case, replace the node's value with its in-order successor (or predecessor) and recursively delete that successor.

Pro tip: Mention that using the in-order successor maintains BST properties and discuss trade-offs like tree height and balancing. Also, clarify that the function should return the root of the modified subtree to handle root deletion.

1. Search for the node

Recursively traverse the BST to find the node with the given key, comparing the key with the current node's value.

2. Handle base case

If the node is null, return null; if the key matches, proceed to deletion logic.

3. Case 1 & 2: No child or one child

If the node has no left child, return its right child; if no right child, return its left child. This effectively removes the node.

4. Case 3: Two children

Find the in-order successor (leftmost node in the right subtree), copy its value to the current node, then recursively delete the successor from the right subtree.

5. Return updated root

After recursive calls, return the current node (or new root) to maintain the tree structure.

Key Points to Mention

  • Time complexity: O(h) where h is the height of the tree, which is O(log n) for balanced BST and O(n) for skewed tree.
  • Space complexity: O(h) due to recursion stack.
  • In-order successor vs predecessor: both work; successor is commonly used.
  • Handling of duplicate keys: typically assume no duplicates or define a policy.
  • Edge cases: deleting root node, node with one child, node not present.
  • Importance of returning the root to handle root deletion and maintain tree links.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.