Tripadvisor Interview Question

Verify a BT is a BST.

Interview Answers

Anonymous

Nov 19, 2015

do an inorder traversal, and check if the returned array is sorted. If not, then it is not BST

Anonymous

Aug 31, 2015

Recursively traverse the tree from the root, and verify that every node has a lesser value on the left, higher value on the right. Return false whenever you encounter otherwise