Step-By-Step Directions From a Binary Tree Node to Another | 2 Approaches | Leetcode 2096

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



Duration: 34:05
9,338 views
409


Whatsapp Community Link : https://www.whatsapp.com/channel/0029...
This is the 46th Video of our Playlist "BINARY TREE : Popular Interview Problems" by codestorywithMIK

In this video we will try to solve a very good Tree Problem : Step-By-Step Directions From a Binary Tree Node to Another| 2 Approaches | Leetcode 2096 | 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 : Step-By-Step Directions From a Binary Tree Node to Another| 2 Approaches | Leetcode 2096 | codestorywithMIK
Company Tags : AMAZON
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Intervie...
Leetcode Link : https://leetcode.com/problems/step-by...


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 :
Approach 1 (Using LCA)

Time Complexity: O(n)
Space Complexity: O(n)
Description:
Lowest Common Ancestor (LCA): Find the LCA of the startValue and destValue nodes using a recursive approach. The LCA is the node that is an ancestor to both target nodes and is farthest from the root.
Find Paths: From the LCA, find paths to both startValue and destValue. These paths are recorded as sequences of 'L' (left) and 'R' (right).
Construct Result: Convert the path from LCA to startValue to 'U' (upward moves) and append the path from LCA to destValue directly to form the result.
Steps:
Find the LCA of startValue and destValue.
Find the path from the LCA to startValue and destValue.
Construct the result by moving up from startValue to LCA and then following the path to destValue.
Approach 2 (Without finding LCA)

Time Complexity: O(n)
Space Complexity: O(n)
Description:
Find Paths: Find paths from the root to both startValue and destValue directly. These paths are recorded as sequences of 'L' (left) and 'R' (right).
Identify Common Path: Determine the common path prefix between the two paths.
Construct Result: From the point where the paths diverge, convert the path from the common ancestor to startValue to 'U' (upward moves) and append the remaining path to destValue directly to form the result.
Steps:
Find the path from the root to startValue and destValue.
Identify the length of the common path prefix.
Construct the result by moving up from startValue to the common ancestor and then following the path to destValue.
Both approaches efficiently determine the sequence of moves required to navigate from startValue to destValue in a binary tree, with the first approach leveraging the concept of LCA and the second approach avoiding explicit LCA computation by directly comparing paths from the root.


✨ 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




Other Videos By codestorywithMIK


2024-07-26Second Minimum Time to Reach Destination | 2 Approaches | FULL DRY RUN | Leetcode 2045
2024-07-24Find the City With the Smallest Number of Neighbors at a Threshold Distance | 3 Ways | Leetcode 1334
2024-07-22Sort the Jumbled Numbers | 2 Approaches | Leetcode 2191 | codestorywithMIK
2024-07-20Minimum Operations to Make Array Equal to Target | Minimum Number of Increments|Leetcode 3229 & 1526
2024-07-19Build a Matrix With Conditions | BFS | DFS | Detailed Explanation | Leetcode 2392 | codestorywithMIK
2024-07-19Palindrome Partitioning | Using Blue Print | DP On Strings | Leetcode 131 | DP Concepts & Qns-27
2024-07-18Find Valid Matrix Given Row and Column Sums | Simple Approach | Leetcode 1605 | codestorywithMIK
2024-07-18Number of Good Leaf Nodes Pairs | Simple DFS | Dry Run | Leetcode 1530 | codestorywithMIK
2024-07-17Lucky Numbers in a Matrix | 2 Approaches | Dry Run | Leetcode 1380 | codestorywithMIK
2024-07-16Number of Good Leaf Nodes Pairs | Using Graph And BFS | Dry Run | Leetcode 1530 | codestorywithMIK
2024-07-14Step-By-Step Directions From a Binary Tree Node to Another | 2 Approaches | Leetcode 2096
2024-07-13Create Binary Tree From Descriptions | Simplest Approach | Leetcode 2196 | codestorywithMIK
2024-07-12Range Sum Query - Mutable | Leetcode 307 | Segment Tree Concepts & Qns | Video 8 | codestorywithMIK
2024-07-12Number of Atoms | Made Easy | Full Dry Run | Leetcode 726 | Google | codestorywithMIK
2024-07-12Minimum Cost for Cutting Cake I & II | Thought Process | Leetcode 3218 | 3219 | codestorywithMIK
2024-07-12Robot Collisions | Made Easy | Dry Run | Leetcode 2751 | codestorywithMIK
2024-07-12Minimum Insertion Steps to Make a String Palindrome | Blue Print | DP On Strings | Leetcode 1312
2024-07-11Maximum Score From Removing Substrings | 2 Approaches | With Proof | Leetcode 1717
2024-07-09Reverse Substrings Between Each Pair of Parentheses | 2 Approaches | Leetcode 1190 |codestorywithMIK
2024-07-08Crawler Log Folder | 2 Approaches | Dry Runs | Leetcode 1598 | codestorywithMIK
2024-07-07Average Waiting Time | Simple Simulation | Leetcode 1701 | codestorywithMIK