Skip to content

Practice Binary Tree Cameras

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#968
LeetCode Problem

Binary Tree Cameras

Problem Statement

You are given the root of a binary tree. We install cameras on the tree nodes where each camera at a node can monitor its parent, itself, and its immediate children. Return the minimum number of cameras needed to monitor all nodes of the tree.

Source: Binary Tree Cameras on LeetCode. Use the original task for its coding environment and submissions.

Examples

# 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

Constraints

The number of nodes in the tree is in the range [1, 1000].
Node.val == 0

Related LeetCode Problems

Practice more problems similar to Binary Tree Cameras.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.