DSA Tracker

Hard

Minimum Time to Burn Binary Tree

A hard Binary Trees problem included in Striver A2Z. Below: the roles whose interviews prioritise this topic, and how to practise it.

Topic
Binary Trees
Sheets
1
Core for
4 roles
Platform
GeeksforGeeks

The problem

Given the root of a binary tree and a target node, find the minimum time required to burn the entire tree starting from the target node. At each minute, all adjacent unburned nodes catch fire.

Example 1

Input
root=[1,2,3,4,5,6,7], start=3
Output
3
Why
Minute 0 burns 3, minute 1 burns 1,6,7, minute 2 burns 2, minute 3 burns 4 and 5.

Example 2

Input
root=[1], start=1
Output
0
Why
Only one node, already burned at time 0.

Example 3

Input
root=[1,2,null,3,null,4,null,5], start=2
Output
3
Why
Starting from 2: burns 1 at minute 1, 3 at minute 2, 4 at minute 3. Node 5 is reached through the chain.

Constraints

  • The number of nodes is in the range [1, 105].
  • 1 <= Node.val <= 105
  • All values are unique.

How to think about it

Updated 2026-09-09

The time to burn the entire tree is the maximum shortest distance from the start node to any node in the tree. Treat the tree as an unweighted undirected graph by mapping parents. A breadth-first search radiating outward from the start node measures how many layer expansions are required until no unburned nodes remain.

Approaches, worst first

  1. Depth calculations via LCA and heights

    time O(n) · space O(h)

    Find height of tree from target downwards, and compute distances to all ancestors and opposite subtrees recursively. Requires maintaining multiple subtree height routines and ancestor path distances.

  2. Graph conversion with BFS infectionWrite this one

    time O(n) · space O(n)

    Traverse tree once to build parent references and locate start node. Initialize a queue with start node and mark it visited. In each round, burn all unvisited adjacent nodes (left, right, parent). Increment time only if at least one new node catches fire.

Where people lose marks · 3
  • Incrementing the minute counter when the queue pops nodes whose neighbours are already all visited; time must only increase if new nodes were actually ignited.
  • Forgetting parent connections limits fire spread exclusively to descendants, leaving ancestors and their opposite subtrees unreached.
  • Single-node tree edge case: starting on a tree with only one node takes 0 minutes.

The theory behind it

Binary Trees — the ground this problem stands on. All Binary Trees problems

What Binary Trees is

A binary tree is a branching data structure that starts at a single top node called the root, like an upside-down family tree. Every node holds a piece of data and can branch out to at most two children below it, known as the left child and the right child. Because there is no ordering rule about which values go left or right, finding a specific item can require checking every single node in the entire tree.

When to reach for it

Reach for binary trees when problems present hierarchical data with left and right child pointers. Questions asking for tree height, maximum depth, path sums from root to leaf, diameter, lowest common ancestor, or checking whether two trees are mirror reflections of each other all signal binary tree traversals. Any problem asking to inspect or reconstruct a tree layer by layer or path by path belongs here.

How the pattern works

Think recursively by focusing on what a single node must do. If the current node is null, return the base answer immediately. Otherwise, ask the left child for its result, ask the right child for its result, and combine both answers with the current node value before returning up to the parent. For horizontal scans, use a queue to read nodes layer by layer, measuring the queue length at the start of each layer to group nodes by depth.

What each operation costs

OperationTime
traverse all nodes using recursion or queueO(n)
search for an arbitrary value in an unordered treeO(n)
call stack memory on balanced treeO(log n)
call stack memory on skewed treeO(n)
What usually goes wrong with Binary Trees
  • Dereferencing left or right child pointers without checking if the current node is null, throwing null pointer errors on empty trees or leaf nodes.
  • Defining a leaf node incorrectly by stopping when either child is null instead of checking that both left and right children are simultaneously null.
  • Computing tree diameter by taking left height plus right height inside a recursive helper without updating a global maximum across every visited node.

Which roles need this problem

Binary Trees is a core topic for these 4 roles — if you're targeting one of them, this problem is early in your path, not optional.

Secondary for 5 more roles, including Full-Stack Developer, Android Developer, iOS Developer.

Companies that have asked it

Tags taken from the problem's own GeeksforGeeks page — not a copied list.

Track this in your role's order

Pick your target role and all 370 problems — including this one — resequence to what that interview actually asks. Free.

Start free

More Binary Trees problems

Problem set and role mapping as of .