LC 968 Binary Tree Cameras | Greedy + DFS HARD | Explained
Автор: The Optimal Approach
Загружено: 2026-03-14
Просмотров: 6
Описание:
Welcome to Day 16 of the 75 Hard DSA Challenge
In this video, I solve and explain LeetCode 968 – Binary Tree Cameras, a classic HARD greedy + DFS problem where we must place the minimum number of cameras to monitor every node in a binary tree.
What you’ll learn in this video:
Why greedy placement works on trees
Understanding node states (covered / uncovered / camera)
How postorder DFS helps make optimal decisions
When and where to place cameras
Handling the root node edge case
Writing a clean recursive solution
Key Concept:
This problem is solved using a postorder DFS with state tracking.
Each node returns one of three states:
0 → Not covered
1 → Covered (no camera)
2 → Has camera
Rules:
If any child is uncovered → place camera
If any child has camera → node is covered
Otherwise → node is uncovered
At the end, we check the root and place a camera if needed.
This greedy DFS guarantees the minimum number of cameras.
75 Hard sheet: https://docs.google.com/spreadsheets/...
Problem Link: https://leetcode.com/problems/binary-...
Solution Link: https://github.com/sibasundarj8/75-Ha...
If you find this helpful, consider liking the video and subscribing to follow the complete 75-day HARD DSA journey 🔥
#leetcodehard #binarytree #dfs #greedy #treedp #recursion #75harddsachallenge #75hardchallenge #dsahardproblems #leetcode968 #codinginterview #coding #dsainjava #dsa #dsahard
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: