SCVMM - Or Server tools - whatever found that the person .......
Microsoft Interview Questions and Answers
(Continued from previous question...)
53. SCVMM - Or Server tools - whatever found that the person .......
Question:
SCVMM - Or Server tools - whatever
found that the person is barely knowledgeable in algorithms.
Find the element closest to a given input element in a BST
maybe an answer:
int returnClosest(node *root, int elem)
{
node *curr=root;
int smaller=-1,bigger=99999;
while(curr){
if(curr->data < elem){
smaller=curr;
curr=curr->right;
}
else if(curr->data > elem){
bigger=curr;
curr=curr->left;
}
else //equals
return curr->data;
} //end of while
return min(elem-smaller,bigger-elem);
}
(Continued on next question...)
Other Interview Questions
|