Number of Good Leaf Nodes Pairs | Using Graph And BFS | Dry Run | Leetcode 1530 | codestorywithMIK
Whatsapp Community Link : https://www.whatsapp.com/channel/0029...
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
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Intervie...
Leetcode Link : https://leetcode.com/problems/number-...
My DP Concepts Playlist : • Roadmap for DP | How to Start DP ? | ...
My Graph Concepts Playlist : • Graph Concepts & Qns - 1 : Graph will...
My Recursion Concepts Playlist : • Introduction | Recursion Concepts And...
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Intervie...
Instagram : / codestorywithmik
Facebook : / 100090524295846
Twitter : / cswithmik
Subscribe to my channel : / @codestorywithmik
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
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