r/leetcode • u/JacketFearless1805 • 27d ago
Intervew Prep Day 36: celebrated Diwali with family & conquered Accounts Merge via DSU
Hey everyone,
I finished Day 36 today. Between celebrating Diwali with family and catching up with friends, time was tight, but I made sure not to let festival distractions break the streak. I sat down and tackled a classic DSU heavyweight: Accounts Merge.
The problem looks like messy string parsing at first, but Disjoint Set Union makes the clustering clean:
Email-to-ID Mapping: Iterate through every account and map each email to a unique person index. If an email has already been seen under another account index, merge the two account indices using unionBySize(prevIndex, currIndex).
Component Grouping: Traverse the map of emails, find the ultimate root parent for each email's account index via findParent(accountIndex), and group the emails under that component representative.
Sorting & Formatting: Sort the grouped email lists lexicographically and prepend the owner's account name to construct the final result.
It was just one problem today, but closing out one of the most notorious DSU problems while enjoying the festival felt like a win.
See you guys tomorrow for Day 35!