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
The task is to print the left view of a binary tree, which contains the nodes visible when viewed from the left side.
Traverse the binary tree level by level and keep track of the leftmost node at each...read more
Help your peers!
Add answer anonymously...
SquadStack Product Engineer interview questions & answers
A Product Engineer was asked Q. Reverse Words in a String: Problem Statement You are given a string of length N....read more
A Product Engineer was asked Q. What is an Inner Join?
A Product Engineer was asked Q. How would you design a parking lot system?
Popular interview questions of Product Engineer
A Product Engineer was asked Q1. Reverse Words in a String: Problem Statement You are given a string of length N....read more
A Product Engineer was asked Q2. What is an Inner Join?
A Product Engineer was asked Q3. How would you design a parking lot system?
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

