Grokking 75: Top Coding Interview Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Solution: Amount of Time for Binary Tree to Be Infected
On this page

Problem Statement

You are given the root of a binary tree with unique values and an integer start.

At the start time (minute 0), an infection starts from the node with the value start.

Each minute, a node becomes infected if:

  • It is currently uninfected.
  • It is adjacent to an infected node.

Return the number of minutes required for the entire tree to become infected.

Examples

Example 1:

  • Input: root = [1, 2, 3, null, 4, 5, 6], start = 3
  • Expected Output: 3
  • Explanation: The tree structure is:
        1
       / \
      2   3
    

.....

.....

.....

Like the course? Get enrolled and start learning!

On this page