Minimum Time to Burn a Binary Tree from a Leaf Node

You are given a binary tree with 'N' unique nodes, and a specific start node from where the fire will begin. The task is to determine the time in minutes required to burn the entire tree, starting from the given node.

The fire travels from the burning node to its adjacent nodes each minute, burning them down.

Input:

First line: Elements of the tree in level order form, separated by space. Use -1 for null nodes. 
Second line: Value of the start node.

Output:

An integer representing the time in minutes to burn the whole tree.

Example:

Input:
1 2 3 -1 -1 4 5 -1 -1 -1 -1
3
Output:
2
Explanation:
- Tree visualization:
1
/ \
2 3
/ \
4 5
- Start from Node 3:
0th minute: Node 3 burns.
1st minute: Nodes 1, 4, 5 burn.
2nd minute: Node 2 burns.
Entire tree burns in 2 minutes.

Constraints:

  • 1 ≤ N ≤ 105
  • 1 ≤ Value of Tree Node ≤ 109
  • 1 ≤ Value of Start Node ≤ 109
  • Time limit: 1 second
Note:
Input is handled in function, no need to print the output.
AnswerBot
4mo

The task is to determine the time in minutes required to burn the entire binary tree starting from a given node.

  • Traverse the tree from the given start node to calculate the time taken to burn the enti...read more

Help your peers!
Select
Add answer anonymously...

PhonePe Software Developer interview questions & answers

A Software Developer was asked 6mo agoQ. Why do you want to join?
A Software Developer was asked 8mo agoQ. Given a graph, write a function to perform a Breadth-First Search (BFS) traversa...read more
A Software Developer was asked Q. Insertion in AVL Tree Problem Statement You are required to implement an AVL Tre...read more

Popular interview questions of Software Developer

A Software Developer was asked 6mo agoQ1. Why do you want to join?
A Software Developer was asked Q2. Insertion in AVL Tree Problem Statement You are required to implement an AVL Tre...read more
A Software Developer was asked Q3. Unlock the Briefcase Problem Statement You have a briefcase secured by a lock wi...read more
PhonePe Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits