 All Problems
Trim a Binary Search Tree
medium
trees
binary search tree
recursion
amazon
google
facebook

Given the root of a BST and bounds [low, high], trim the tree so all values are within [low, high]. Return the root of the trimmed tree. Output the level-order traversal.

Example 1:

Input: 1 0 2
Bounds: 1 2
Output: 1 2

Example 2:

Input: 3 0 4 null 2 null null null null 1
Bounds: 1 3
Output: 3 2 1

Input format: Line 1: level-order tree. Line 2: low high.

Output format: Level-order of trimmed tree.

Run to check your code against the sample cases, or submit to run every case