Amazon interview question

How would you check a BST?

Interview Answers

Anonymous

21 Aug 2012

Looks like the prev solution needs a correction. Something like this? public boolean checkBst(Node n) { if (n == null) return true; if (checkBst(n.left)) { if ( checkBst(n.right)) { boolean isBst = 1; if (n.left != null){ isBst *= n.left.data n.data; } return isBst; } } return false; }

Anonymous

16 Mar 2012

public boolean checkBst(Node n) { if (n == null) return true; if (checkBst(n.left)) { if ( checkBst(n.right)) { boolean isBst = false; if (n.left != null){ isBst = n.left.data n.data; } return isBst; } } return false; }