Tap here to switch tabs
Problem
Submissions

Problem: Amount of Time for Binary Tree to Be Infected

Amount of Time for Binary Tree to Be Infected starts at a chosen node in a binary tree. Return how many minutes it takes to infect every node through parent-child connections.

Statement

You are given the root of a binary tree with unique values, and an integer start. At minute 00, the infection begins at the node with the value start.

Each minute, every infected node spreads the infection to all adjacent nodes that are not yet infected. An adjacent node is defined as a node’s parent, its left child, or its right child.

Return the total number of minutes needed to infect the entire binary tree.

Constraints:

  • The number of nodes in the tree is in the range [1,105][1, 10^5].

  • 1≤1 \leq Node.val ≤105\leq 10^5

  • Each node has a unique value.

  • A node with a value of start exists in the tree.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Amount of Time for Binary Tree to Be Infected

Amount of Time for Binary Tree to Be Infected starts at a chosen node in a binary tree. Return how many minutes it takes to infect every node through parent-child connections.

Statement

You are given the root of a binary tree with unique values, and an integer start. At minute 00, the infection begins at the node with the value start.

Each minute, every infected node spreads the infection to all adjacent nodes that are not yet infected. An adjacent node is defined as a node’s parent, its left child, or its right child.

Return the total number of minutes needed to infect the entire binary tree.

Constraints:

  • The number of nodes in the tree is in the range [1,105][1, 10^5].

  • 1≤1 \leq Node.val ≤105\leq 10^5

  • Each node has a unique value.

  • A node with a value of start exists in the tree.