Fire Spread in Binary Tree
Goldman Sachs interview questions · Medium · Coding round · 6 tests
A fire breaks out at one node of a binary tree. You receive the tree's root, where every node holds a distinct value, together with the value of the node where the fire begins.
At second 0 just that starting node is on fire. During each following second,
every node already on fire ignites each of its neighbours:
- the left child,
- the right child, and
- the parent node.
Compute how many seconds pass before every node in the tree is on fire.
Run your code with Ctrl+Enter to see results.