Challenge: Trim the Tree Nodes Outside Range

Try solving the problem of trimming the tree nodes which are not in the range of given minimum and maximum numbers.

Problem

Given a BST and a range, delete all nodes outside of that range.

Input

A BST and minimum and maximum values.

Output

An updated BST.

Sample input

Range:

min = 3
max = 9

Binary tree:

Get hands-on with 1400+ tech skills courses.