Amazon.com Interview Question
1,566 Interview Reviews |
Back to all Amazon.com Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Software Development Engineer In Test at Amazon.com:
Coding question - given a binary tree, write code to count the sum off all siblings.
See more for this Amazon.com Software Development Engineer In Test Interview
Helpful Question?
Yes |
No
Inappropriate?
Answers & Comments (2)
0 of 1 people found this helpful
if(root == null)
return 0;
return 1 + totalNumberOfNodes(root.left) + totalNumberOfNodes(root.right);
}
Helpful Answer?
Yes |
No
Inappropriate?
To comment on this
question,
Sign In with Facebook or
Sign Up



0 of 1 people found this helpful
by needajob:
<?php
// O(n) times
function countSiblings($tree,$sum)
{
if($tree->value == null)
return $sum;
$sum = $sum + $tree->value;
countSiblings($tree->left,$sum);
countSiblings($tree->right,$sum);
}
?>