filmov
tv
Delete Nodes And Return Forest Solved | Simple Approach | Google | Leetcode 1110 | codestorywithMIK

Показать описание
This is the 7th Video of our Playlist "BINARY TREE : Popular Interview Problems" by codestorywithMIK
In this video we will try to solve a very good Tree Problem : Delete Nodes And Return Forest Solved | Simple Approach | Google | Amazon | Leetcode 1110 | 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 : Delete Nodes And Return Forest Solved | Simple Approach | Google | Amazon | Leetcode 1110 | codestorywithMIK
Company Tags : GOOGLE, AMAZON
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
Summary :
The given approach for deleting nodes from a binary tree and returning the forest of remaining trees involves a recursive helper function and a set for efficient node deletion lookup. Here’s a summary of the approach:
Convert to Set: The to_delete list of integers is converted to an unordered set st for efficient lookup of nodes to be deleted.
Recursive Deletion: The deleteHelper function is recursively called to traverse the tree. During traversal:
For each node, the function recursively processes its left and right children.
If a node's value is found in the set st, the node is deleted:
Its left and right children (if not null) are added to the result list as new roots.
The function returns NULL to effectively delete the current node.
If a node's value is not in the set, the function returns the node itself.
Check Root: After the initial call to deleteHelper, the root is checked:
If the root's value is not in the set st, it is added to the result list as a new root.
Result List: The function delNodes returns the list of remaining tree roots after deletions.
This approach ensures that nodes are deleted correctly while their children become new tree roots, forming a forest as the final result.
✨ Timelines✨
00:00 - Introduction
0:15 - Problem Explanation
2:05 - Explanaining Thought Process
9:25 - Coding it up
#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 : Delete Nodes And Return Forest Solved | Simple Approach | Google | Amazon | Leetcode 1110 | 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 : Delete Nodes And Return Forest Solved | Simple Approach | Google | Amazon | Leetcode 1110 | codestorywithMIK
Company Tags : GOOGLE, AMAZON
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
Summary :
The given approach for deleting nodes from a binary tree and returning the forest of remaining trees involves a recursive helper function and a set for efficient node deletion lookup. Here’s a summary of the approach:
Convert to Set: The to_delete list of integers is converted to an unordered set st for efficient lookup of nodes to be deleted.
Recursive Deletion: The deleteHelper function is recursively called to traverse the tree. During traversal:
For each node, the function recursively processes its left and right children.
If a node's value is found in the set st, the node is deleted:
Its left and right children (if not null) are added to the result list as new roots.
The function returns NULL to effectively delete the current node.
If a node's value is not in the set, the function returns the node itself.
Check Root: After the initial call to deleteHelper, the root is checked:
If the root's value is not in the set st, it is added to the result list as a new root.
Result List: The function delNodes returns the list of remaining tree roots after deletions.
This approach ensures that nodes are deleted correctly while their children become new tree roots, forming a forest as the final result.
✨ Timelines✨
00:00 - Introduction
0:15 - Problem Explanation
2:05 - Explanaining Thought Process
9:25 - Coding it up
#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
Комментарии