FastPrepMinimum Cameras to Monitor a Binary Tree
Problems/Minimum Cameras to Monitor a Binary Tree

Minimum Cameras to Monitor a Binary Tree

OYO Rooms logoOYO Rooms● HardNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an OYO Rooms new grad phone screen. The report names Binary Tree Cameras and asks for the fewest cameras needed to watch every node. We used the usual coverage: a camera watches its own node, its parent, and its children. We added the input limits, the range of node values, the rule that the tree is not empty, the examples, and the function signature. Our version is about 90% the same as the reported question.

Given a nonempty binary tree root, return the minimum number of cameras needed to monitor every node. A camera placed at a node monitors that node, its parent if one exists, and its immediate left and right children if they exist.

Place at most one camera at any node. Node values do not affect coverage; equal values may belong to different nodes. The input uses the usual level-order tree array with null for missing children.

Function

minimumTreeCameras(root: TreeNode) → int

Examples

Example 1

root = [0,0,null,0,0]return = 1
root
0000

One camera at the root's left child covers that child, the root, and both grandchildren.

Example 2

root = [0,0,0,0,0,0,0]return = 2
root
0000000

Cameras at both children of the root cover all seven nodes. A single camera cannot cover leaves in both subtrees.

Constraints

  • The tree contains 1 to 1000 non-null nodes.
  • The canonical level-order array has 1 to 1999 slots, including nulls.
  • Every non-null node value is an integer from 0 through 1000.
  • The root is non-null and every serialized non-null node is attached to the tree.

More OYO Rooms Phone Screen questions

  • Minimum Rooms for Meeting IntervalsPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Binary Tree CamerasAmazon · OA · PHONE SCREEN
  • Minimum Rounds to Inform an N-ary TreeRippling · PHONE SCREENRippling interview questions
  • Minimum Satellite Data Transfer IterationsHSBC · OAHSBC interview questions
  • Split Array to Minimize the Largest SumNation with NaMo · PHONE SCREEN
  • File Encryption Tree OptimizationDatabricks · PHONE SCREEN · ONSITE INTERVIEWDatabricks interview questions
  • Lowest Common Manager for Employee GroupsGoogle · PHONE SCREENGoogle interview questions
  • Stock Profit With One, Unlimited, or Two TradesAdobe · PHONE SCREENAdobe interview questions
  • Maximum Path Sum Between Marked NodesDoorDash · PHONE SCREENDoorDash interview questions
  • House Robber IIIOkta · PHONE SCREENOkta interview questions
  • House Robber IIIGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
See OYO Rooms hiring insights
Saved
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public int minimumTreeCameras(TreeNode root) {
        // Write your code here
    }
}
Checking account…