Skip to content

Practice Amount of Time for Binary Tree to Be Infected

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2385
LeetCode Problem

Amount of Time for Binary Tree to Be Infected

Problem Statement

At minute 0, infect the node whose unique value is start. Each following minute, infection spreads simultaneously from infected nodes to their uninfected parent or child neighbors. Return the time until every node of root is infected.

Source: Amount of Time for Binary Tree to Be Infected on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
root = [1,5,3,null,4,10,6,9,2], start = 3
Output
4

# Example 2

Input
root = [1], start = 1
Output
0

Constraints

The number of nodes in the tree is in the range [1, 10^5].
1 <= Node.val <= 10^5
Each node has a unique value.
A node with a value of start exists in the tree.

Related LeetCode Problems

Practice more problems similar to Amount of Time for Binary Tree to Be Infected.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.