Boundary Traversal Problem Statement
Given a binary tree of integers, your task is to return the boundary nodes of this binary tree in an anti-clockwise direction starting from the root node.
Example:
Input:
T = 1
Data for binary tree (in level order):
1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1
Output:
1 2 4 7 6 3
Explanation:
The boundary nodes are the nodes on the left boundary, followed by leaves, followed by right boundary nodes without repeating any nodes.
Constraints:
1 ≤ T ≤ 102
1 ≤ N ≤ 212
- 'N' is the total number of nodes in the binary tree.
- Time Limit: 1 sec
Note:
The input format was provided for clarity. Each test case should be processed with the entire node sequence given in a single line, separated by spaces where -1 denotes null nodes.

AnswerBot
4mo
Return the boundary nodes of a binary tree in an anti-clockwise direction starting from the root node.
Traverse the left boundary nodes in a top-down manner
Traverse the leaf nodes from left to right
Tra...read more
Help your peers!
Add answer anonymously...
Amazon Software Developer interview questions & answers
A Software Developer was asked 1mo agoQ. What is HTML?
A Software Developer was asked 1mo agoQ. What is MySQL?
A Software Developer was asked 3mo agoQ. What is the system design for the cart feature in an e-commerce website?
Popular interview questions of Software Developer
A Software Developer was asked 1mo agoQ1. What is HTML?
A Software Developer was asked 1mo agoQ2. What is MySQL?
A Software Developer was asked 3mo agoQ3. What is the system design for the cart feature in an e-commerce website?
Top HR questions asked in Amazon Software Developer
A Software Developer was asked 1mo agoQ1. Tell me about a time you had to get to the root cause of a problem
A Software Developer was asked 5mo agoQ2. What are the short-term and long-term goals for the team or organization?
A Software Developer was asked 5mo agoQ3. Why do you want to work at Amazon?
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

