Deepest Left Leaf Node Problem Statement

You are provided with a binary tree consisting of 'N' nodes. Your goal is to identify the deepest leaf node that is a left child of some node within the given binary tree.

Input:

The first line of input contains an integer 'T', indicating the number of test cases that follow.  For each test case, the first line includes the values of the Binary Tree supplied in level order format. Nodes' values are separated by a single space. If a node is absent, '-1' is used in its place. 

Output:

For each test case, output the data value of the deepest leaf node that is a left child of any parent node. Ensure to print the output for each test case on a new line. 

Example:

Input:
3
5 1
6 2 0 8
-1 -1 7 4 -1 -1 -1 -1
-1 -1 -1 -1
Output:
7

Constraints:

  • 1 <= T <= 5
  • 1 <= N <= 3 * (10 ^ 3)
  • 1 <= nodeVal <= 10 ^ 9
  • Time Limit: 1 sec.

Note:

The deepest left leaf node is defined as the leaf node that is both a left child of any node and present at the maximum depth in the tree. If there are multiple candidates, return the one with the maximum value. A binary tree is defined such that each node can have at most two children, and the input tree is guaranteed to be non-empty. Additionally, multiple nodes may share the same value, and all values are positive.
AnswerBot
2d

Identify the deepest left leaf node in a binary tree.

  • Traverse the binary tree in level order to find the deepest left leaf node.

  • Keep track of the maximum depth and the value of the deepest left leaf n...read more

Help your peers!
Add answer anonymously...
Freshworks Graduate Trainee 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