Good Subtrees | GFG | POTD | 5th May 2023 | DFS | Java | C++ | Problem Of The Day
Автор: Prativa TECH
Загружено: 2023-05-04
Просмотров: 130
Описание:
The video solves Problem Of The Day question " Good Subtrees " asked on GeeksForGeeks on 5th May 2023 .
The logic behind the approach used in the solution is based on the fact that a subtree is a subset of the binary tree rooted at a given node, and that the number of distinct values in a subtree is the number of distinct values in the union of the sets of distinct values of its left and right subtrees, as well as the value of the root node itself.
Therefore, we can traverse the binary tree using DFS and, at each node, recursively traverse its left and right subtrees to get the sets of distinct values in each subtree. We can then create a new set and add all the values from the left and right sets as well as the current node's value to it. If the size of the new set is less than or equal to k, we increment the count of good subtrees.
By the end of the traversal, the count variable will contain the number of good subtrees in the binary tree.
GFG POTD 5th May 2023 :
https://practice.geeksforgeeks.org/pr...
Java | C++ solution Code Link :
https://docs.google.com/document/d/1u...
Java Interview Series :
• Core Java Interview Questions
GFG POTD series : • Problem Of The Day | 31st Jan 2023 | Geeks...
Java -17 series : • Java 17 - Introduction
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: