1110. Delete Nodes And Return Forest || LeetCode POTD || Explained in HINDI

Поділитися
Вставка
  • Опубліковано 7 вер 2024
  • Instagram link:- / reelcoding
    Don't click:- / @reelcoding
    Approach:
    Use Depth-First Search (DFS):
    Perform a DFS traversal of the tree to handle the deletion process. Keep track of nodes to be deleted using a set for quick lookup.
    Handle Node Deletion:
    During the DFS traversal, if a node needs to be deleted, ensure its children are considered as new roots if they are not deleted themselves.
    Maintain a list to store the roots of the remaining trees.
    Construct the Result:
    Initialize the traversal from the root, treating it as a potential new root if it is not deleted. Recursively apply the deletion process.
    Time and Space Complexity:
    Time Complexity:
    The DFS traversal visits each node exactly once, resulting in a time complexity of O(n), where n is the number of nodes in the tree.
    Space Complexity:
    The space complexity is O(n) due to the recursion stack during the DFS traversal and the storage for the set of nodes to be deleted.
    Background Music for Videos: www.bluetreeau...
    Whether you're new to problem-solving or seeking insights into Java programming techniques, this video offers valuable insights into tackling similar challenges effectively.
    Do join with me guys for daily problem solving on LeetCode.
    Please like and subscribe this channel and share among your friends, it helps me to motivate and bring more videos for you guys. ❤️❤️
    Soon, DSA batch (Hinglish) is going to launch on this channel. So, do subscribe so that you will get the notification for all new videos.👍👍🔔🔔.
    Do comment if any doubts left. Thank you 😊
    #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa
    #CodingExplanation #AlgorithmTutorial #JavaProgramming #DataStructures #DynamicProgramming #CodeExplanation #ProgrammingTutorial #AlgorithmExplanation #TechTutorial #LearnToCode #ProblemSolving #ProgrammingConcepts #SoftwareDevelopment #TechEducation #CodingCommunity #CodeBreakdown #ComputerScience
    #JavaTutorial #AlgorithmAnalysis #EducationalContent
    1110. Delete Nodes And Return Forest
    Leetcode 1110
    Delete Nodes And Return Forest
    Leetcode daily challenge
    Leetcode potd
    1110 Delete Nodes And Return Forest
    leetcode potd today solution
    leetcode potd today
    leetcode grind
    leetcode questions for interview
    leetcode series
    leetcode hindi

КОМЕНТАРІ • 4

  • @reelcoding
    @reelcoding  Місяць тому +1

    Code link:- leetcode.com/problems/delete-nodes-and-return-forest/solutions/5489890/java-solution-explained-in-hindi/

  • @devissrani1076
    @devissrani1076 Місяць тому +1

    Suppose i did post order traversal and upon checking every node if it's value matches any value in to_delete and I EQUATED THAT NODE TO NULL and stored its left and right into list . Why this doesn't work .........

    • @reelcoding
      @reelcoding  Місяць тому

      Equating a node to null in a post-order traversal won’t work correctly because you lose reference to its left and right children once you set the node to null.

    • @reelcoding
      @reelcoding  Місяць тому

      1.Loss of Reference:When you set a node to null, you lose the ability to access its left and right children. This is because the node itself is the reference to its children. Setting it to null means you can no longer traverse from that node to its children.
      2.Incorrect Tree Structure:If you set a node to null, the tree structure becomes invalid at that point. The parent node will still hold a reference to the node you set to null, which breaks the link in the tree hierarchy.
      3.Invalid Updates: During the traversal, if you try to access children of a node that has been set to null, it will lead to null pointer exceptions. The tree needs to maintain proper references between parent and child nodes to traverse correctly.