Write a function to validate a BST .......
Microsoft Interview Questions and Answers
(Continued from previous question...)
110. Write a function to validate a BST .......
Question:
Write a function to validate a BST. do it without a queue. What is the complexity of your solution?
maybe an answer:
bool isValidBST(node *p, int minAllowedValue, int maxAllowedValue)
{
if(p == null)
return true;
if(p->value < minAllowedValue || p->value > maxAllowedValue)
return false;
return isValidBST(p->left, minAllowedValue, p->value)
&& isValidBST(p->right, p->value, maxAllowedValue);
}
(Continued on next question...)
Other Interview Questions
|