Meta / Amazon / Google / Microsoft| Trim a Binary Search Tree | LeetCode-669: Medium | JavaScript Implementation

JavaScript Implementation:

var trimBST = function(root, low, high) {
const util = (node)=>{
if(!node) return null;

node.left = util(node.left)
node.right = util(node.right)

if(node.val < low) return node.right
if(node.val > high) return node.left
return node

}
root = util(root)
return root
};

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store