Leetcode 1722. Minimize Hamming Distance After Swap Operations
DSU • DISJOINT SETS | Compet...
leetcode.com/problems/minimiz...
Connect with me on LinkedIn :- / mohammad-f-bb4886157
Telegram Group t.me/LeadCoding
Leetcode Hard :- • Hard
Leetcode Medium :- • Medium
Leetcode Easy :- • Easy
Пікірлер: 18
Thank you for putting this up. Pretty nice approach.
Superb Explanation
Took me 2 hrs to understand the solution clearly as i didnt know DSU But it was worth it..
Nice Explanation
Khatarnak Logic
buddy pls explain problem 4th also 1723. Find Minimum Time to Finish All Jobs
I think DSU will define the time complexity so it will be O(nlogn)
How did you get the idea of maintaining maps of unions and incrementing it for source and decrementing for target? Please share it. It is also one of the important aspect of this problem. Also share other ways to do it instead of maps of unions.
@mohammadfraz
3 жыл бұрын
I usually go for maps when I have to maintain a count. Here I wanted to used kind of 2D map, so I used a map of map.
at 8:04 how there is a difference at 3 and 2 ie 4 and 2 I hope why we are interchanging them unnecessarily
why ans /=2? could you please explain?
@jayasingh5519
3 жыл бұрын
Because actually you are adding the number of differences twice, If there are three ones in source and two ones are in target the difference is 1 i.e there will be one position mismatch or you can say one '1'will never be matched and suppose at that mismatch position, there is 5 in target array then you will add abs(-1) for 5 too which will make count 2 for just one mismatch. 😊
why didn't you used unordered_map instead of map, it's complexity is O(1)?
@mohammadfraz
3 жыл бұрын
yes You can use that.
Hey can you tell me which application you are using for the explanation. name ?
@rajawatlks
3 жыл бұрын
Bhai.... reply BHI Karna hota y
@ajaydabas7872
3 жыл бұрын
@@rajawatlks Microsoft OneNote
why its ans/2 not ans only?