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
Chowdam Mounika
2y
Print a single integer denoting the time in minute that will be taken to born the whole tree
Help your peers!
Add answer anonymously...
Top Wipro Data Analyst interview questions & answers
Popular interview questions of Data Analyst
Top HR questions asked in Wipro Data Analyst
Stay ahead in your career. Get AmbitionBox app
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
Get AmbitionBox app