Reported September 2026
Amazontree

Binary Tree Cameras

Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Amazon OA. Under 2s to a working solution.
Founder's read

The whole problem lives in a binary tree, and Amazon reported it in September 2026 as Binary Tree Cameras. You get a root, every node has value 0, and you need the fewest cameras so each node is watched. Values are noise. Only the shape matters. It's a tree problem with a greedy heart, and it's the kind that looks like DP until someone shows you the shortcut. If you've got an invite and 48 hours, learn the three-state post-order idea below. StealthCoder sits invisibly on your screen during the live OA as a safety net if your mind goes blank on the states.

The problem

You are given the root of a binary tree. You may install cameras on its nodes.
A camera installed at a node monitors that node, its parent if one exists, and its immediate children.
Return the minimum number of cameras needed so that every node in the tree is monitored.

Function
minCameraCover(root: TreeNode) → int

Examples
Example 1
root = [0,0,null,0,0]
return = 1
Place one camera on the second node in the level-order representation. It monitors its parent, itself, and both of its children, so every node is covered.
Example 2
root = [0,0,null,0,null,0,null,null,0]
return = 2
No single camera can monitor the entire chain-like tree. Two cameras placed at suitable internal nodes are sufficient.
Example 3
root = [0]
return = 1
The only node must be monitored, so installing one camera on the root is optimal.

Constraints
The tree contains between 1 and 1000 nodes.
Every node has value 0.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a post-order DFS where each node returns one of three states: not covered, has a camera, or covered without a camera. Leaves return not covered. If any child is not covered, the parent must get a camera and returns has camera. If any child has a camera, the parent is covered. Otherwise the parent returns not covered and waits for its own parent. Null nodes count as covered, which keeps leaves from getting cameras. The common pitfall is placing cameras on leaves, which wastes one per leaf pair. The other is forgetting the root: if it comes back not covered, add one more camera. This runs in O(n) time and O(h) space. Up to 1000 nodes means recursion depth is fine. If you freeze mid-OA, StealthCoder can hand you the state machine so you can type it out and check it against the examples.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Binary Tree Cameras cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as binary tree cameras. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Amazon's OA.

Amazon reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Binary Tree Cameras FAQ

What's the trick in Binary Tree Cameras?+

Work bottom-up with post-order DFS and put cameras on parents of leaves, never on leaves. Each node returns a state: not covered, has camera, or covered. A parent installs a camera only when a child is not covered. This greedy choice covers the most nodes per camera.

Is this a DP problem or a greedy problem?+

Both work. A full DP tracks min cameras for each node under several states. The greedy three-state DFS is simpler and runs in O(n). For an OA, write the greedy version because it's shorter and has fewer places to make mistakes.

What's the most common bug?+

Forgetting to handle the root. After the DFS, if the root's state is not covered, you need one extra camera. Example 3, a single node, tests exactly this. The second bug is treating null children as uncovered, which forces needless cameras on leaves.

How hard is this really for an Amazon OA?+

It's labeled hard, but the code is about fifteen lines once you know the states. The difficulty is seeing the greedy order, not writing it. If you've seen the leaf-parent idea before, it's a ten minute solve. If not, it can eat the whole session.

How do I prep this in 48 hours?+

Write the three-state DFS from memory twice. Trace Example 1 and Example 2 by hand, marking each node's state. Then test a single node and a straight chain. That covers the edge cases the OA is likely to probe. Don't spend time on other tree DP variants.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Amazon.

OA at Amazon?
Invisible during screen share
Get it