Minimize Cameras That Cover a Tree Node and Its Neighbors
Quick Overview
Minimize Cameras That Cover a Tree Node and Its Neighbors. A camera installed on a tree node monitors that node, its parent if present, and its immediate children.
Minimize Cameras That Cover a Tree Node and Its Neighbors
Company: Amazon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Other
### Problem
A camera installed on a tree node monitors that node, its parent if present, and its immediate children. Return the fewest cameras needed to cover every node of the given binary tree. Node values do not affect camera coverage.
```cpp
class Solution {
public:
int minCameraCover(TreeNode* root);
};
```
### Examples
**Example 1:**
```text
Input: root = [0,0,0]
Output: 1
Explanation: One camera at the root covers all three nodes.
```
**Example 2:**
```text
Input: root = [0,0,0,0,null,null,0]
Output: 2
Explanation: Cameras at the root's two children cover all five nodes. The two outer leaves are four edges apart, so one camera cannot cover both.
```
### Constraints
- The tree contains1 to1000 nodes.
- Every node value is0.
### Contract considerations
Each camera has radius one edge, not an entire-subtree view. All node values are0 under the source contract.
```hint Read the boundary condition
Distinguish a covered root with no camera from a root waiting for its parent to cover it.
```
### Boundary reminders
Each camera has radius one edge, not an entire-subtree view. All node values are0 under the source contract.
Overview: Minimize Cameras That Cover a Tree Node and Its Neighbors. A camera installed on a tree node monitors that node, its parent if present, and its immediate children.
Minimize Cameras That Cover a Tree Node and Its Neighbors
Amazon
Source window: 0–3 months · as of Oct 21, 2026
hardSoftware EngineerOtherCoding & Algorithms
0
0
Problem
A camera installed on a tree node monitors that node, its parent if present, and its immediate children. Return the fewest cameras needed to cover every node of the given binary tree. Node values do not affect camera coverage.
class Solution {
public:
int minCameraCover(TreeNode* root);
};
Examples
Example 1:
Input: root = [0,0,0]
Output: 1
Explanation: One camera at the root covers all three nodes.
Example 2:
Input: root = [0,0,0,0,null,null,0]
Output: 2
Explanation: Cameras at the root's two children cover all five nodes. The two outer leaves are four edges apart, so one camera cannot cover both.
Constraints
The tree contains1 to1000 nodes.
Every node value is0.
Contract considerations
Each camera has radius one edge, not an entire-subtree view. All node values are0 under the source contract.
Boundary reminders
Each camera has radius one edge, not an entire-subtree view. All node values are0 under the source contract.