Meta Interview Question

Tell me about yourself. Write code to check if a BST is valid or not.

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)); }

1