Loading problem…
You may place cameras on nodes of a nonempty binary tree. A camera monitors the node where it is installed, its parent (if present), and its immediate children. It does not monitor grandchildren.
Return the minimum cameras needed to monitor every node. All node values are zero and carry no additional meaning.
Example arrays use level-order notation with null for missing children. Your function receives a TreeNode object.
Example 1:
Example 2:
Example 3: