Meta interview question

write a function to check the validity of a binary search tree

Interview Answers

Anonymous

16 Nov 2016

Recursion. - checkTree(TreeNode* root, int upperLimit, int lowerLimit) - initially, set upperLimit to INT_MAX and lowerlimit to INT_MIN; - Whenever you go left, update the upperLimit to the current node value - Whenever you go right, update the lowerLimit to the current node value - At each level, check that the current node value is between the upper and lower limits. If a node doesn't fit this criteria, return false

5

Anonymous

15 Nov 2016

An in-order traversal of a BST would result in a list of numbers in ascending order.

1

Anonymous

10 Nov 2016

It doesn't matter how I answered this question. I believe these types of interview questions don't test a candidate's true problem solving skills. I've interviewed for some startups, and the questions that they have given are always structured to be relevant to the company somehow, not these purely memorization problems. When has anyone ever needed to balance a BST at an actual company? being a good software engineer doesn't mean that you need to know all these algorithms, how to flip strings, etc. Yes knowledge of data structures and algorithms are important, but this is not the way to test them.