Binary Tree Cameras

Problem Description

You are given the root of a binary tree. Install the minimum number of cameras on nodes such that every node is monitored. A camera at a node monitors: itself, its parent, and its immediate children. Pattern: Greedy + post-order DFS with 3 states: - 0 = node is NOT covered - 1 = node is covered (no camera here) - 2 = node HAS a camera Key insight: null nodes return 1 (covered). If any child is 0, place camera here (return 2). If any child has a camera (2), this node is covered (return 1). Otherwise return 0 (needs coverage from parent). Example 1: Input: root = [0,0,null,0,0] Output: 1 Example 2: Input: root = [0,0,null,0,null,0,null,null,0] Output: 2

Example Test Cases

Example 1
Input: [[[0,0,null,0,0]]]
Expected: 1
Example 2
Input: [[[0,0,null,0,null,0,null,null,0]]]
Expected: 2

Run your code to see the results