Amazon Interview Question: Main question was verifying w... | Glassdoor

Interview Question

Software Engineer Intern Interview(Student Candidate) Penn State University, PA

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 Answer

2 Answers


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.

Interview Candidate on Apr 2, 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.

Khoa on Apr 5, 2014

Add Answers or Comments

To comment on this, Sign In or Sign Up.