Binary Tree Cameras

Problem Place the minimum number of cameras on binary-tree nodes so every node is monitored; a camera monitors its parent, itself, and its immediate children.

Input / Output

  • Input: tree root. Output: minimum camera count.

Constraints

  • Up to 1000 nodes; O(n) greedy DFS expected — the DP formulation also accepted.

Example

  • [0,0,null,0,0] → 1 (camera on the middle node); [0,0,null,0,null,0,null,null,0] → 2.
asked …
LeaderboardSalaryAccount