
Asked in Amazon
Left View of a Binary Tree
Given a binary tree, your task is to print the left view of the tree. The left view of a binary tree contains the nodes visible when the tree is viewed from the left side.
Input:
The input consists of elements in a level order form. Values of nodes are separated by a single space in a single line. Use -1 to represent null nodes.
Output:
The output will be a single line with the data values of the nodes visible in the left view of the tree, separated by a single space.
Example:
Input:
1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1
Output:
1 2 4 7
Explanation:
The input represents a binary tree in level order. After constructing the tree, the left view contains the nodes 1, 2, 4, and 7, as these are the nodes visible from the left side.
Constraints:
0 <= N <= 10^5
1 <= data <= 10^5
- The sequence represents a binary tree where 'N' is the total number of nodes and 'data' is the value of each node.
Note:
The input format explains how to interpret and construct the binary tree from the level order input. All nodes at the last level being null (-1) indicates the end of input.

AnswerBot
4mo
Print the left view of a binary tree, containing nodes visible from the left side.
Traverse the tree level by level and print the first node of each level.
Use a queue to keep track of nodes at each lev...read more
Help your peers!
Add answer anonymously...
Top Software Developer Interview Questions Asked at Amazon
Q. Could you describe the process for designing a data structure that allows for al...read more
Q. What is Java?
Q. Given two strings s and t, return true if they are equal when both are typed int...read more
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for Amazon Software Developer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
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

