• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
August 21, 2024 0

PROBLEM OF THE DAY : 20/08/2024 | Burning Tree

Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Nitin Kaplas We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Tree but also build up problem-solving skills.

Given a binary tree and a node data called target. Find the minimum time required to burn the complete binary tree if the target is set on fire. It is known that in 1 second all nodes connected to a given node get burned. That is its left child, right child, and parent.
Note: The tree contains unique values.


Examples : 

Input:                1        /   \      2      3    /  \      \   4    5      6       / \      \      7   8      9                   \                   10 Target Node = 8 Output: 7 Explanation: If leaf with the value 8 is set on fire. After 1 sec: 5 is set on fire. After 2 sec: 2, 7 are set to fire. After 3 sec: 4, 1 are set to fire. After 4 sec: 3 is set to fire. After 5 sec: 6 is set to fire. After 6 sec: 9 is set to fire. After 7 sec: 10 is set to fire. It takes 7s to burn the complete tree.

Give the problem a try before going through the video. All the best!!!
Problem Link: https://practice.geeksforgeeks.org/problems/burning-tree/1