Description
Place cameras on tree nodes to monitor all nodes. A camera at node monitors parent, itself, and children. Minimize cameras.
Examples
Input:
root = [0,0,null,0,0]Output:
1Explanation:
One camera at second node monitors all.
Input:
root = [0]Output:
1Explanation:
Single node tree requires one camera. The camera at the root monitors itself, covering all nodes in the tree.
Input:
root = [0,0,0,null,null,0,0]Output:
2Explanation:
Complete binary tree with 5 nodes. One camera at the root monitors the root and both children. One camera at the right child monitors itself and its two children. This placement ensures all nodes are monitored with minimum cameras.
Constraints
- •
1 ≤ number of nodes ≤ 1000