filmov
tv
Number of Good Leaf Nodes Pairs | Using Graph And BFS | Dry Run | Leetcode 1530 | codestorywithMIK
![preview_player](https://i.ytimg.com/vi/vrbJ7aDuK-A/maxresdefault.jpg)
Показать описание
This is the 47th Video of our Playlist "BINARY TREE : Popular Interview Problems" by codestorywithMIK
In this video we will try to solve a very good Tree Problem : Number of Good Leaf Nodes Pairs | Using Graph And BFS | Dry Run | Leetcode 1530 | codestorywithMIK
I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.
Problem Name : Number of Good Leaf Nodes Pairs | Using Graph And BFS | Dry Run | Leetcode 1530 | codestorywithMIK
Company Tags : Will update soon
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
Summary :
The key methods are makeGraph and countPairs.
Converts a binary tree into an undirected graph using an adjacency list (adj).
Marks leaf nodes by adding them to a set (st).
Takes root as the current node, prev as the previous node, and recursively processes the tree.
If the current node (root) is a leaf node, it is added to the set of leaves.
Connects the current node with its parent (prev) in the adjacency list.
*countPairs(TreeNode root, int distance)**:
Initializes an adjacency list (adj) and a set of leaf nodes (st).
Calls makeGraph to populate these structures.
Uses BFS (Breadth-First Search) to find pairs of leaf nodes within the specified distance.
For each leaf node, it performs BFS up to the given distance, checking if other leaf nodes are reachable within this distance.
Counts and returns the number of valid leaf node pairs, dividing by 2 to avoid double-counting.
✨ Timelines✨
00:00 - Introduction
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #newyear2024
In this video we will try to solve a very good Tree Problem : Number of Good Leaf Nodes Pairs | Using Graph And BFS | Dry Run | Leetcode 1530 | codestorywithMIK
I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.
Problem Name : Number of Good Leaf Nodes Pairs | Using Graph And BFS | Dry Run | Leetcode 1530 | codestorywithMIK
Company Tags : Will update soon
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
Summary :
The key methods are makeGraph and countPairs.
Converts a binary tree into an undirected graph using an adjacency list (adj).
Marks leaf nodes by adding them to a set (st).
Takes root as the current node, prev as the previous node, and recursively processes the tree.
If the current node (root) is a leaf node, it is added to the set of leaves.
Connects the current node with its parent (prev) in the adjacency list.
*countPairs(TreeNode root, int distance)**:
Initializes an adjacency list (adj) and a set of leaf nodes (st).
Calls makeGraph to populate these structures.
Uses BFS (Breadth-First Search) to find pairs of leaf nodes within the specified distance.
For each leaf node, it performs BFS up to the given distance, checking if other leaf nodes are reachable within this distance.
Counts and returns the number of valid leaf node pairs, dividing by 2 to avoid double-counting.
✨ Timelines✨
00:00 - Introduction
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #newyear2024
Комментарии