Error
|
|
---|---|
@Ibrahim Nash | 5765 |
@blackshadows | 5715 |
@akhayrutdinov | 5111 |
@mb1973 | 4993 |
@Quandray | 4944 |
@saiujwal13083 | 4506 |
@sanjay05 | 3762 |
@marius_valentin_dragoi | 3516 |
@sushant_a | 3459 |
@verma_ji | 3341 |
@KshamaGupta | 3318 |
Complete Leaderboard | |
|
|
@aroranayan999 | 1286 |
@bt8816103042 | 739 |
@rohitanand | 495 |
@codeantik | 479 |
@shalinibhataniya1097 | 472 |
@amrutakashikar2 | 464 |
@thealchemist627 | 456 |
@akashkale117 | 453 |
@shivanandp12345678910 | 453 |
@dalwainazism125 | 453 |
@SherlockHolmes3 | 447 |
Complete Leaderboard |
Given a Binary Tree of size N, find all the nodes which don't have any sibling. Root node can not have a sibling.
Example 1:
Input : 37 / 20 / 113 Output: 20 113 Explanation: 20 and 113 dont have any siblings.
Example 2:
Input : 1 / \ 2 3 Output: -1 Explanation: Every node has a sibling.
Your Task:
You dont need to read input or print anything. Complete the function noSibling() which takes the root of the tree as input parameter and returns a list of integers containing all the nodes that don't have a sibling in sorted order. If all nodes have a sibling, then the returning list should contain only one element -1.
Expected Time Complexity: O(NlogN)
Expected Auxiliary Space: O(Height of the tree)
Constraints:
1 ≤ N ≤ 10^4
All nodes have distinct values.
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes