1579. Remove Max Number of Edges to Keep Graph Fully Traversable || LeetCode POTD || HINDI

Поділитися
Вставка
  • Опубліковано 17 жов 2024
  • Instagram link:- / reelcoding
    / @reelcoding
    Approach:-
    Initialization:
    We initialize two DSU instances: one for Alice and one for Bob.
    We also sort the edges such that the edges that can be used by both Alice and Bob (type 3) are processed first. This ensures we maximize the shared usage of these edges.
    Processing Edges:
    We iterate through the edges and use the union operation to connect nodes.
    If an edge connects two components (nodes) that are already connected, it can be considered redundant and counted as a removable edge.
    We handle type 3 edges first, which both Alice and Bob can use, followed by type 2 (Bob only) and type 1 (Alice only).
    Checking Connectivity:
    After processing all edges, we check if both Alice and Bob have connected all nodes (i.e., each has used n-1 edges). If either hasn't, it's impossible to connect all nodes, and we return -1.
    Time and Space Complexity
    Time Complexity:
    Sorting the edges takes O(m log m), where m is the number of edges.
    Union and find operations in DSU are nearly constant time, O(α(n)), where α is the inverse Ackermann function.
    Therefore, the overall time complexity is O(m log m + m α(n)).
    Space Complexity:
    Storing the DSU structures for Alice and Bob takes O(n) each.
    Additional space for storing the edges is O(m).
    Hence, the overall space complexity is O(n + m).
    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
    1579. Remove Max Number of Edges to Keep Graph Fully Traversable
    Leetcode 1579
    All Ancestors of a Node in a Directed Acyclic Graph
    Leetcode daily challenge
    Leetcode potd
    1579 Remove Max Number of Edges to Keep Graph Fully Traversable
    leetcode potd today solution
    leetcode potd today
    leetcode grind
    leetcode questions for interview
    leetcode series
    leetcode hindi

КОМЕНТАРІ • 1

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

    Code link:- leetcode.com/problems/remove-max-number-of-edges-to-keep-graph-fully-traversable/solutions/5391610/java-solution-explained-in-hindi/