Amazon Interview Question

Main question was verifying whether a binary tree was a BST, given the function header that looked like public boolean isBST(root). He stated no other functions could be created and that child nodes did not have links to their parents.

Interview Answers

Anonymous

Apr 2, 2014

He was looking for me to use a helper function to pass the parent's value in. boolean isBST(Node root) { return isBSTHelper(root.left, root.value, isLeft) && isBSTHelper(root.right, root.value, isRight); } something similar to this. Since he told me I could not use extra functions I could not come up with an answer which is why I am bitter / negative about this interview.

Anonymous

Apr 6, 2014

Basically, what you would have in isBST is the stop condition (i.e. if left < current-node < right), then recursively whether isBST(left) && isBST(right) is true.