Welcome to the daily solving of our PROBLEM OF THE DAY with Yash Dwivedi. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Binary Tree but also build up problem-solving skills.
In this problem, we are given a Binary Tree of n nodes, find all the nodes that don't have any siblings. You need to return a list of integers containing all the nodes that don't have a sibling in sorted order (Increasing).
Two nodes are said to be siblings if they are present at the same level, and their parents are the same.
Note: The root node can not have a sibling so it cannot be included in our answer.
Example :
Input :
37
/
20
/
113
Output:
20 113
Explanation:
Nodes 20 and 113 dont have any siblings.
Give the problem a try before going through the video. All the best!!!
Problem Link: https://www.geeksforgeeks.org/problems/print-all-nodes-that-dont-have-sibling/1
Solution IDE Link: https://ide.geeksforgeeks.org/online-cpp14-compiler/153ae375-3f25-48f8-9e08-cd4e213e98d3