Minimum Cost Walk in Weighted Graph | Thought Process | DSU | Leetcode 3108 | codestorywithMIK

Subscribers:
92,300
Published on ● Video Link: https://www.youtube.com/watch?v=B3Wgf-g6i-k



Duration: 44:02
1,424 views
77


Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
This is the 45thVideo of our Playlist "GRAPHS : Popular Interview Problems".

In this video we will try to solve a very good problem : Valid Parenthesis String | Leetcode 678

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 : Minimum Cost Walk in Weighted Graph | Detailed Thought Process | Leetcode 3108 | codestorywithMIK
Company Tags : Will update soon
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Graph/Disjoint%20Set/Minimum%20Cost%20Walk%20in%20Weighted%20Graph.cpp
Leetcode Link : https://leetcode.com/problems/minimum-cost-walk-in-weighted-graph/


My DP Concepts Playlist : https://youtu.be/7eLMOE1jnls
My Graph Concepts Playlist : https://youtu.be/5JGiZnr6B5w
My Recursion Concepts Playlist : https://www.youtube.com/watch?v=pfb1Zduesi8&list=PLpIkg8OmuX-IBcXsfITH5ql0Lqci1MYPM
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Interview_DS_Algo
Instagram : https://www.instagram.com/codestorywithmik/
Facebook : https://www.facebook.com/people/codestorywithmik/100090524295846/
Twitter : https://twitter.com/CSwithMIK
Subscribe to my channel : https://www.youtube.com/@codestorywithMIK

Approach Summary :
The approach implemented in the provided Java code solves a problem involving finding the minimum cost in a graph represented by nodes and edges, and then answering queries based on this minimum cost. Here's a summary of the approach:

1. **Union-Find Data Structure**: The solution employs the union-find data structure to efficiently handle connectivity information between nodes in the graph. It maintains an array `parent`, where each element initially points to itself, representing its own component. The `find` method finds the root of the component to which a node belongs, with path compression optimization for efficiency. The `union` method merges two components by setting one component's parent to the root of the other component.

2. **Minimum Cost Calculation**: The solution iterates through the edges of the graph. For each edge, it determines the root nodes of the connected components using the `find` method. It then updates the minimum cost of the merged component using bitwise AND operation with the existing cost. The `cost` array stores the minimum cost for each component.

3. **Answering Queries**: After calculating the minimum cost for each component, the solution processes the queries. For each query, it determines the root nodes of the nodes involved and compares their root nodes. If the root nodes are the same, it retrieves the minimum cost for that component from the `cost` array. If the nodes are in different components or are identical, appropriate values (either the minimum cost or 0) are added to the result array.

Overall, this approach efficiently handles both the computation of minimum costs and answering queries in the given graph.

╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

✨ 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-04-17Island Perimeter | 3 Approaches | Google | Leetcode 463 | codestorywithMIK
2024-04-16Smallest String Starting From Leaf | DFS | BFS | Google | Leetcode 988 | codestorywithMIK
2024-04-14Edit Distance | Recursion | Memo | Bottom Up | DP On Strings | Leetcode 72 | DP Concepts & Qns-21
2024-04-13Sum of Left Leaves | 2 Approaches | META | Leetcode 404 | codestorywithMIK
2024-04-12Maximal Rectangle | Multiple Hidden Problems | Intuition | Leetcode 85 | codestorywithMIK
2024-04-12One Love = CODING ❤️👨🏻‍💻
2024-04-10Remove K Digits | Intuition | Dry Run | Leetcode 402 | codestorywithMIK
2024-04-09Reveal Cards In Increasing Order | 2 Approaches | Leetcode 950 | codestorywithMIK
2024-04-09Time Needed to Buy Tickets | 3 Approaches | Leetcode 2073 | codestorywithMIK
2024-04-07Number of Students Unable to Eat Lunch | 2 Approaches | Leetcode 1700 | codestorywithMIK
2024-04-07Minimum Cost Walk in Weighted Graph | Thought Process | DSU | Leetcode 3108 | codestorywithMIK
2024-04-07Valid Parenthesis String | 4 Detailed Approaches | Leetcode 678 | codestorywithMIK
2024-04-06Print Shortest Common Supersequence | DP On Strings | Leetcode 1092 | DP Concepts & Qns-21
2024-04-05Minimum Remove to Make Valid Parentheses | 3 Detailed Approaches | Leetcode 1249 | codestorywithMIK
2024-04-03Maximum Nesting Depth of the Parentheses | 2 Approaches | Leetcode 1614 | codestorywithMIK
2024-04-01Isomorphic Strings | Simple Thought Process | Leetcode 205| LinkedIn | codestorywithMIK
2024-03-31Length of Last Word | 2 Ways | Leetcode 58 | Amazon | codestorywithMIK
2024-03-31April, we are coming 🔥🔥🔥 #leetcode #maths #leetcodequestionandanswers #codestorywithmik
2024-03-30Count Alternating Subarrays | Super Easy | Leetcode 3031 | Weekly Contest 391 | codestorywithMIK
2024-03-30Subarrays with K Different Integers | Approach-2 | One Pass | Leetcode 992 | codestorywithMIK
2024-03-29Subarrays with K Different Integers | Approach-1 | With Reasons | Leetcode 992 | codestorywithMIK