GK
BAN USER
Comments (4)
Reputation -5
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
-1
of 1 vote
Node structure will contain "level" field and "parent" field. Perform BFS on the tree. Keep track of the node that was inserted just before the current node. Once the target node is found look for level change. If the parent of the target node and the "before" node is the same after level changes, then the target node has no cousin. Else, the "before" node is the rightmost cousin.
- GK October 23, 2013Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Count the number of nodes in the left half of the BST which is O(lg n). If this count >=k then the kth smallest element is on the left side, so search the left half else search the right half.
- GK May 15, 2014