Loading...
Engaged Employer
You are given a binary tree as input , find whether the tree is a BST or not .
Anonymous
Take the inorder traversal of the tree . If its a sorted list , its bst .
bool isBST(Node* root) { if (root == NULL) return true; bool lbst = true; bool rbst = true; if (root->left) { if(root->left->val val) return false; lbst = isBST(root->left); } if (lbst && root->right) { if (root->right->val > root->val) return false; rbst = isBST(root->right); } return rbst && lbst;
Check out your Company Bowl for anonymous work chats.
Get actionable career advice tailored to you by joining more bowls.
Stay ahead in opportunities and insider tips by following your dream companies.
Get personalized job recommendations and updates by starting your searches.