Problem 41 of 75

Search in a Binary Search Tree

EasyNot solved yetInterview me on this
Before you code · which pattern fits?

The problem

You are given the root of a binary search tree (BST) and an integer val. Find the node whose value equals val and return the subtree rooted at that node (null if it does not exist).

([4,2,7,1,3], 2) → [2,1,3] ([4,2,7,1,3], 5) → []

Your solution runs against 2 unit tests, including edge and large-value cases.

Loading...

Test console · 2 unit tests

Submit your code to run it against all 2 unit tests. Results appear here.

JavaScript, TypeScript & Python run sandboxed in your browser; other languages run on the execution server. Your code is saved locally as you type.

Hint

Reference solution

Video explanation

Search in a Binary Search Tree, explainedNick White