Problem Statement: Sibling Nodes

You are provided with a Binary Tree consisting of 'N' nodes, where each node holds an integer value. Your objective is to identify and list all nodes that do not possess a sibling.

Note:
1. A node ‘U’ is defined as a sibling of node ‘V’ if both nodes share the same parent.
2. The root node is considered a sibling node.

Input:

The first input line contains an integer 'T', indicating the number of test cases or queries.

Each test case comprises a single line of space-separated integers representing the Binary Tree in level order. Each value corresponds to a node, and '-1' represents a null node.

Output:

For each test case, output a single line containing the values of all nodes without siblings, sorted in ascending order.
The output for each test case should appear on a new line.

Example:

Input:

1
1 3 8 5 2 7 -1 -1 -1 -1 -1

Output:

7

Constraints:

  • 1 <= T <= 5
  • 0 <= N <= 3000
  • 0 <= node data <= 109

Where 'T' is the number of test cases and 'N' is the number of nodes in the tree.

Time limit: 1 second.

Note:
You are not required to handle printing the output; this is managed for you. Implement the function to achieve the desired outputs.
AnswerBot
4mo

Identify and list nodes in a Binary Tree that do not have a sibling.

  • Traverse the Binary Tree in level order to identify sibling nodes.

  • Keep track of nodes without siblings and output them in ascending ...read more

Help your peers!
Select
Add answer anonymously...

Directi Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. Merge Overlapping Intervals Problem Statement Given a specified number of interv...read more
A Software Developer Intern was asked Q. Design a streaming service similar to Netflix and explain how it onboard new con...read more
A Software Developer Intern was asked Q. Postfix Expression Evaluation Problem Statement Given a postfix expression, your...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. Merge Overlapping Intervals Problem Statement Given a specified number of interv...read more
A Software Developer Intern was asked Q2. Design a streaming service similar to Netflix and explain how it onboard new con...read more
A Software Developer Intern was asked Q3. Postfix Expression Evaluation Problem Statement Given a postfix expression, your...read more
Directi Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits