PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Google

Delete a Node From a Search Tree

Last updated: May 5, 2026

Quick Overview

This question evaluates understanding and implementation of binary search tree operations, specifically node deletion while preserving BST ordering, along with related skills in tree traversal and pointer or recursive manipulation.

  • hard
  • Google
  • Coding & Algorithms
  • Software Engineer

Delete a Node From a Search Tree

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

You are given the root of a binary search tree and an integer `key`. Delete the node whose value equals `key`, if it exists, while preserving the binary search tree property. Return the possibly new root of the tree. A binary search tree is defined as follows: for every node, all values in its left subtree are smaller than the node's value, and all values in its right subtree are larger than the node's value. Consider all cases: - The node does not exist. - The node is a leaf. - The node has exactly one child. - The node has two children. - The node to delete is the root. Example: ```text Input tree: 5 / \ 3 6 / \ \ 2 4 7 key = 3 One valid output tree: 5 / \ 4 6 / \ 2 7 ``` Implement a function that performs the deletion and returns the updated root.

Quick Answer: This question evaluates understanding and implementation of binary search tree operations, specifically node deletion while preserving BST ordering, along with related skills in tree traversal and pointer or recursive manipulation.

Related Interview Questions

  • Solve Flower Placement and Directory Deletion - Google (medium)
  • Compute Turnstile Crossing Times - Google (hard)
  • Simulate In-Place Cellular State Updates - Google (hard)
  • Determine Whether a Word Exists in a Graph - Google (medium)
  • Implement Checksums and Feature Rollout Evaluation - Google (medium)
Google logo
Google
Apr 29, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
2
0

You are given the root of a binary search tree and an integer key. Delete the node whose value equals key, if it exists, while preserving the binary search tree property. Return the possibly new root of the tree.

A binary search tree is defined as follows: for every node, all values in its left subtree are smaller than the node's value, and all values in its right subtree are larger than the node's value.

Consider all cases:

  • The node does not exist.
  • The node is a leaf.
  • The node has exactly one child.
  • The node has two children.
  • The node to delete is the root.

Example:

Input tree:
        5
       / \
      3   6
     / \   \
    2   4   7

key = 3

One valid output tree:
        5
       / \
      4   6
     /     \
    2       7

Implement a function that performs the deletion and returns the updated root.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Google•More Software Engineer•Google Software Engineer•Google Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.