Count the nodes at distance K from leaf | 2 Approaches | Simple Dry Run | GFG POTD

Subscribers:
92,300
Published on ● Video Link: https://www.youtube.com/watch?v=Lzvqu8WPNh8



Duration: 45:49
1,474 views
109


Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
This is the 39th Video of our Playlist "Binary Tree : Popular Interview Problems".
In this video we will try to solve two very good map problems - Count the nodes at distance K from leaf | GFG POTD

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 : Count the nodes at distance K from leaf | GFG POTD
Company Tags : Flipkart, Microsoft
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Tree/Count%20the%20nodes%20at%20distance%20K%20from%20leaf.cpp
GfG Link : https://www.geeksforgeeks.org/problems/node-at-distance/1


My DP Concepts Playlist : https://youtu.be/7eLMOE1jnls
My Graph Concepts Playlist : https://youtu.be/5JGiZnr6B5w
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Interview_DS_Algo
Subscribe to my channel : https://www.youtube.com/@codestorywithMIK
Instagram : https://www.instagram.com/codestorywithmik/
Facebook : https://www.facebook.com/people/codestorywithmik/100090524295846/
Twitter : https://twitter.com/CSwithMIK


Part-1 Summary : The method storeRootToLeaf recursively traverses the tree and populates 'paths' with these paths. In the printKDistantfromLeaf method, it initializes an empty set 'st' and uses 'storeRootToLeaf' to populate 'paths'. It then iterates through each path in 'paths', calculates the distance from the leaf node to the target node (considering 'k' distance), and adds the node at that distance to the set 'st'. Finally, it returns the count of unique nodes in the set 'st', representing the nodes at a distance of 'k' from leaf nodes.

Part-2 Summary : The approach contains a method printKDistantfromLeaf intended to return the count of nodes at a specified distance from leaf nodes in a binary tree. The approach uses a recursive function solve to traverse the binary tree, maintaining a path vector and a set to keep track of nodes at the desired distance from leaf nodes. The method takes a root node, a level, a set for results, a vector for the current path, and an integer 'k' as parameters. The function populates the result set with nodes at the required distance and returns the count.

╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

✨ 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 #2024 #newyear




Other Videos By codestorywithMIK


2024-02-13Quick Sort | Simple Story | Story To Code | Recursion Concepts And Questions | Video 9
2024-02-12Find First Palindromic String in the Array | Multiple Ways | Leetcode 2108
2024-02-11Cherry Pickup II | 3 Approaches | Super Detailed | Leetcode 1463
2024-02-10Tumlog saath ho. Bas kaafi hai ❤️ 18K family #codestorywithmik
2024-02-09Palindromic Substrings | Blueprint | Palindrome Problems | 4 Approaches | Leetcode 647
2024-02-08Largest Divisible Subset | LIS Variant | DP Concepts & Qns-18 | Leetcode-368
2024-02-08Merge Sort | Simple Story | Story To Code | Recursion Concepts And Questions | Video 8
2024-02-07Perfect Squares | Bottom UP | Made Easy | Google | Leetcode 279
2024-02-07Minimum Time to Revert Word to Initial State | Part I | Part II | KMP | Leetcode 3029 | 3031
2024-02-06Tower Of Hanoi | Simple Story | Story To Code | Recursion Concepts And Questions | Video 7
2024-02-06Count the nodes at distance K from leaf | 2 Approaches | Simple Dry Run | GFG POTD
2024-02-05Tail Recursion | Tail call Optimisation | Examples | Recursion Concepts And Questions | Video 5
2024-02-05Time Complexity | Space Complexity | Examples | Recursion Concepts And Questions | Video 4
2024-02-05Recursion Tree | Call Stack | Recursion Concepts And Questions | Video 3
2024-02-05Recursion Leap Of Faith | Examples | Recursion Concepts And Questions | Video 2
2024-02-05Introduction | Recursion Concepts And Questions | Video 1
2024-02-04First Unique Character in a String | Easy | Leetcode 387
2024-02-03Every trip teaches me something. #codestorywithmik
2024-02-02Partition Array for Maximum Sum | Why DP | Recursion | Memo | Bottom Up | Leetcode 1043
2024-02-02Sequential Digits | 2 Approaches | Leetcode 1291
2024-01-31Divide Array Into Arrays With Max Difference| Why Sorting | Google | Leetcode 2966