Determine the Left View of a Binary Tree

You are given a binary tree of integers. Your task is to determine the left view of the binary tree. The left view consists of nodes that are visible when the tree is viewed from the left side.

Example:

Input:
T = 1
Binary Tree Level Order Input: 1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1
Output:
1 2 4 7
Explanation:

The left view of the binary tree is 1, 2, 4, 7 as shown in the image below:

example image

Constraints:

  • 1 <= T <= 100
  • 0 <= N <= 3000
  • 1 <= data <= 105 and data ≠ -1
Note:

You do not need to handle any input/output operations; just implement the function to return the required result.

Be the first one to answer
Add answer anonymously...
Paxcom India Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter