Binary Tree Cameras Problem Statement

Given a binary tree where each node can carry a camera that monitors its parent, itself, and its immediate children, determine the minimum number of cameras needed to monitor all the nodes.

Input:

The first line contains an integer 'T', representing the number of test cases. Each test case is specified as a single line containing elements in level order form, with node values separated by a single space. A -1 represents a null node.

Output:

An integer for each test case, representing the minimum number of cameras needed to monitor all nodes of the tree.

Example:

Input:
1
1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1
Output:
2

Constraints:

  • 1 ≤ T ≤ 5
  • 1 ≤ DATA ≤ 105 and DATA ≠ -1
  • Time limit: 1 sec

Note:

Focus on implementing the function required. Input/output handling is already managed.

AnswerBot
4mo

The problem involves determining the minimum number of cameras needed to monitor all nodes in a binary tree.

  • Implement a function to solve the problem efficiently.

  • Consider the different cases where cam...read more

Help your peers!
Select
Add answer anonymously...

Flipkart Software Developer Intern interview questions & answers

A Software Developer Intern was asked 2mo agoQ. Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]]...read more
A Software Developer Intern was asked 12mo agoQ. Given a matrix, if an element is 0, set its entire row and column to 0.
A Software Developer Intern was asked Q. Design a parking lot application for blind people.

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked 2mo agoQ1. Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]]...read more
A Software Developer Intern was asked 12mo agoQ2. Given a matrix, if an element is 0, set its entire row and column to 0.
A Software Developer Intern was asked Q3. Design a parking lot application for blind people.
Flipkart Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits