Time to Burn Tree Problem

You are given a binary tree consisting of 'N' unique nodes and a start node where the burning will commence. The task is to calculate the time in minutes required to completely burn the entire tree, given that the starting node is guaranteed to be present in the tree.

Every minute, the fire will spread from a burning node to its adjacent nodes, causing them to catch fire.

Input:

The first line contains the elements of the tree in level order form, separated by spaces, where a null node is represented by -1.
The second line contains the value of the start node.

Output:

A single integer representing the time in minutes necessary to burn the entire tree.

Example:

Input:
1 2 3 -1 -1 4 5 -1 -1 -1 -1 
3
Output:
2
Explanation:
Initial state: 
1
/ \
2 3
/ \
4 5

Minute 0: Node 3 starts burning.
Minute 1: Nodes 1, 4, and 5 catch fire.
Minute 2: Node 2 burns. The entire tree is burnt by this time.

Constraints:

  • 1 <= N <= 10^5
  • 1 <= ext{Value of Tree Node} <= 10^9
  • 1 <= ext{Value of Start Node} <= 10^9
  • Time limit: 1 second
AnswerBot
4mo

Calculate the time in minutes required to completely burn a binary tree starting from a given node.

  • Traverse the tree to find the start node and calculate the time for fire to spread to all nodes.

  • Use a...read more

Chowdam Mounika
3y

Print a single integer denoting the time in minute that will be taken to born the whole tree

Help your peers!
Select
Add answer anonymously...

Wipro Data Analyst interview questions & answers

A Data Analyst was asked 1mo agoQ. How can artificial intelligence be utilized in data analysis?
A Data Analyst was asked 2mo agoQ. What are the three types of golden rules of accounting?
A Data Analyst was asked 2mo agoQ. What are the different types of golden rules?

Popular interview questions of Data Analyst

A Data Analyst was asked 1mo agoQ1. How can artificial intelligence be utilized in data analysis?
A Data Analyst was asked 2mo agoQ2. What are the three types of golden rules of accounting?
A Data Analyst was asked 2mo agoQ3. What are the different types of golden rules?

Top HR questions asked in Wipro Data Analyst

A Data Analyst was asked 1mo agoQ1. What's your exceptional quality?
A Data Analyst was asked 2mo agoQ2. Why do you need a job?
A Data Analyst was asked 5mo agoQ3. Can you provide an overview of your background, including your past experiences ...read more
Wipro Data Analyst 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