filmov
tv
Number of Good Leaf Nodes Pairs| Leetcode 1530 in Java| Must do Tree Questions | MAANG Interview |
![preview_player](https://i.ytimg.com/vi/j_IHKRaMiH4/sddefault.jpg)
Показать описание
In this question we are given the root of a binary tree and an integer distance. A pair of two different leaf nodes of a binary tree is said to be good if the length of the shortest path between them is less than or equal to distance.
Return the number of good leaf node pairs in the tree.
Here my approach is bottom up approach, so i am writing a util function that returns the distances of the leaf nodes below it from both side left side as well as right side. before returning the distances i check the left and right side list distance combination sum and check if the sum is less than or equal to Distance parameter, if its is so we are increasing the count gloabal variable by 1 and then i am merging the left and right side list to a list with adding 1 to each value before returning it to the calling parent node as it would be +1 more distance from the leaf nodes below.
finally our count variable would be having answer.
DSA Algorithms :-
Design HLD:-
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview #interviewtips
#interviewpreparation #interview_ds_algo #hinglish
Return the number of good leaf node pairs in the tree.
Here my approach is bottom up approach, so i am writing a util function that returns the distances of the leaf nodes below it from both side left side as well as right side. before returning the distances i check the left and right side list distance combination sum and check if the sum is less than or equal to Distance parameter, if its is so we are increasing the count gloabal variable by 1 and then i am merging the left and right side list to a list with adding 1 to each value before returning it to the calling parent node as it would be +1 more distance from the leaf nodes below.
finally our count variable would be having answer.
DSA Algorithms :-
Design HLD:-
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview #interviewtips
#interviewpreparation #interview_ds_algo #hinglish
Комментарии