Meta Interview Question

Given a root note, confirm whether or not the given tree is a BST.

Interview Answer

Anonymous

Mar 28, 2017

boolean isBST(TreeNode[] root){ return isBSTU(root, Integer.MIN_VALUE, Integer.MAX_VALUE); } boolean isBSTU(TreeNode root, int min, int max){ if(root==null) return true; if(root.valmax) return false; return (isBSTU(root.left,min,root.data-1) && isBSTU(root.right,root,data+1,max)); }