Left View of Binary Tree
Easy Accuracy: 37.86% Submissions: 100k+ Points: 2

Given a Binary Tree, print Left view of it. Left view of a Binary Tree is set of nodes visible when tree is visited from Left side. The task is to complete the function leftView(), which accepts root of the tree as argument.

Left view of following tree is 1 2 4 8.

       /     \
     2        3
   /     \    /    \
  4     5   6    7

Example 1:

 /  \
3    2
Output: 1 3

Example 2:


Output: 10 20 40

Your Task:
You just have to complete the function leftView() that prints the left view. The newline is automatically appended by the driver code.

Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).

0 <= Number of nodes <= 100
1 <= Data of a node <= 1000

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Left View of Binary Tree

Output Window