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, keeping track of the leftmost node at each level
Use a queue for level order traversa...read more
Help your peers!
Add answer anonymously...
Dunzo Software Developer Intern interview questions & answers
A Software Developer Intern was asked Q. Asteroid Collision Problem Description Given an array/list ASTEROIDS representin...read more
A Software Developer Intern was asked Q. Word Break II Problem Statement Given a non-empty string 'S' containing no space...read more
A Software Developer Intern was asked Q. Valid Parentheses Problem Statement Given a string 'STR' consisting solely of th...read more
Popular interview questions of Software Developer Intern
A Software Developer Intern was asked Q1. Asteroid Collision Problem Description Given an array/list ASTEROIDS representin...read more
A Software Developer Intern was asked Q2. Word Break II Problem Statement Given a non-empty string 'S' containing no space...read more
A Software Developer Intern was asked Q3. Valid Parentheses Problem Statement Given a string 'STR' consisting solely of th...read more
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

