Sponsored
Use these hints if you're stuck. Try solving on your own first.
Do a simple tree traversal, try to check if the current node is lonely or not.
Solve with full IDE support and test cases