← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Went into a Google software engineering interview pretty underprepared on the coding side and paid for it. Got hit with a tree problem and it did not go well.

Questions Asked (1)

Q1

Given a root of a binary search tree and a key, delete the node with that key and return the updated tree's root.

Algorithms & Data Structures
Author's notes

Did not practice trees nearly enough before this.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use the BST property to recursively search for the node, then handle deletion based on the number of children: if zero or one child, replace with the child; if two children, replace with the inorder successor (or predecessor) and recursively delete that successor. Return the updated root after each recursive call.

Pro tip: Clarify whether the tree can contain duplicate keys and whether you should use the inorder successor or predecessor—mentioning both shows depth. Also, discuss trade-offs like recursion depth vs. iterative approach for skewed trees.

1. Search for the node

Recursively traverse the BST: if key < node.val, go left; if key > node.val, go right; if equal, you've found the node to delete.

2. Handle base cases

If the node has no children, return null. If it has one child, return that child (which may be null).

3. Handle two children

Find the inorder successor (leftmost node in right subtree) or predecessor (rightmost in left subtree). Replace the node's value with the successor's value, then recursively delete the successor from the right subtree.

4. Return updated root

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

Key Points to Mention

  • BST property: left subtree < node < right subtree
  • Three deletion cases: leaf, one child, two children
  • Inorder successor/predecessor for two-child case
  • Time complexity: O(h) where h is height; worst-case O(n) for skewed tree
  • Space complexity: O(h) for recursion stack
  • Edge cases: empty tree, key not found, root deletion

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