Back to Browse

Maximum Difference Between Node and Ancestor | Brute Force | Optimal | Google | Leetcode 1026

14.1K views
Dec 9, 2022
35:23

Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A This is the 16th Video on our playlist "Binary Tree : Popular Interview Problems".In this video we will try to understand a very good Binary Tree Problem - "Maximum Difference Between Node and Ancestor" ( Leetcode 1026 ) Problem Name : Maximum Difference Between Node and Ancestor Company Tags  : Google, Microsoft, Amazon My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Tree/Maximum%20difference%20between%20node%20and%20its%20ancestor.cpp Leetcode Link  : https://leetcode.com/problems/maximum-difference-between-node-and-ancestor/ GfG Link          : https://www.geeksforgeeks.org/problems/maximum-difference-between-node-and-its-ancestor/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 Approach Summary (Brute Force) - Pick every node and find it's absolute difference with all its ancestors. Update max diff during the journey. Do this for every node and its ancestors. Approach Summary (Optimal Approach) - The key function is maxAncestorDiff, which initializes minimum and maximum values and then calls the recursive function findMaxDiff to compute the maximum difference between any two nodes in the binary tree. The findMaxDiff function traverses the tree recursively, updating the minimum and maximum values encountered along the way, and computes the maximum difference for each subtree. The final result is the maximum difference obtained across all subtrees, and it represents the maximum absolute difference between any two nodes in the given binary tree. ╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗ ║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣ ╠╗║╚╝║║╠╗║╚╣║║║║║═╣ ╚═╩══╩═╩═╩═╩╝╚╩═╩═╝  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

Download

0 formats

No download links available.

Maximum Difference Between Node and Ancestor | Brute Force | Optimal | Google | Leetcode 1026 | NatokHD