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.
Be the first one to answer
Add answer anonymously...
Top Flipkart Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app