Time to Burn a Binary Tree From One Node
Updated
Problem statement
You are given the root of a binary tree with different node values, and the value start of one node. At minute 0 that node catches fire.
Each minute, every burning node sets fire to the nodes it is directly connected to: its left child, its right child and its parent. Return the number of minutes until every node in the tree is burning.
Function
burnTime(root: TreeNode, start: int) → intExamples
Example 1
root = [6,2,9,1,4,null,11,null,null,3,5,10]start = 4return = 5Minute 1: 2, 3 and 5 catch fire. Minute 2: 6 and 1. Minute 3: 9. Minute 4: 11. Minute 5: 10, the last node. Answer: 5.
Example 2
root = [7]start = 7return = 0The only node is already burning at minute 0. Answer: 0.
Example 3
root = [1,2,3,4,5]start = 1return = 2The fire starts at the root. Minute 1 reaches 2 and 3; minute 2 reaches 4 and 5. Answer: 2.
Constraints
- The tree has between
1and500nodes. 1 <= node.val <= 10^5, and all node values are differentstartis the value of a node in the tree
More Adobe Phone Screen questions
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
- All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
- Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
- Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
- Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
- Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- Find All Paths for a Name in a File SystemThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
- Tree Height After Child PromotionSnowflake · PHONE SCREENSnowflake interview questions
- Binary Tree Spiral Level OrderAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Check a Complete Binary TreeGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- Tree DiameterQualcomm · PHONE SCREENQualcomm interview questions
- Frog Position After T SecondsInMobi · PHONE SCREENInMobi interview questions
- Distance Between Two Nodes in a Binary TreeBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Transform and Prune a Mode-Valued Binary TreeGoogle · PHONE SCREENGoogle interview questions
- Team Cost Under a ManagerRippling · PHONE SCREENRippling interview questions
- Symmetric Binary TreeDocuSign · PHONE SCREENDocuSign interview questions