The "Amount of Time for Binary Tree to Be Infected interview question" is a graph traversal problem set within a tree. You are given a binary tree and a starting "infected" node. Every minute, the infection spreads to all adjacent nodes (parent and children). You need to find the total number of minutes it takes for the entire tree to be infected. This is essentially finding the maximum distance from the start node to any other node in the tree.
This "Amount of Time for Binary Tree to Be Infected coding problem" is a favorite of Uber, Amazon, and Google. It tests if a candidate can see that a "tree" is just a restricted "graph." It requires converting the tree's parent-child relationships into bidirectional edges and then performing a standard traversal.
This problem follows the Graph Conversion and Breadth-First Search (BFS) pattern.
Tree: Root 1, Children 2 and 3. Start node: 3.
Practice converting trees to graphs. Once a tree is a graph, you can solve many "distance" or "time" problems using a standard BFS. Remember that the "radius" of a graph starting from a node is just the maximum level in a BFS traversal.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| All Nodes Distance K in Binary Tree | Medium | Solve | |
| Cousins in Binary Tree II | Medium | Solve | |
| Lowest Common Ancestor of Deepest Leaves | Medium | Solve | |
| Correct a Binary Tree | Medium | Solve | |
| Clone Binary Tree With Random Pointer | Medium | Solve |