Hey y’all! Here’s another solution for another frequently asked Meta question, Leetcode 721 Accounts Merge and its variant.
This is absolutely a silent killer of a problem. It’s not only a top question but the requirements of the variant get twisted in the most subtle ways that completely guts the original implementation:
Please note there are situations where you’ll have to come up with the input yourself, so it may be a bit more flexible.
I can confidently say that I officially hate myself after covering this video, IMO it’s a pretty mind-boggling graph problem. Beware that I explain most of the context in the original Leetcode problem and not so much in the variant, so it’s best to watch the whole thing through (unless you have a solid grasp already).
As another footnote, my solution for this problem as well as any of the previous ones are all meant to be intuitive solutions that a candidate would “naturally” come up with on the spot during an interview. It’s not sculpted to perfection and I’m sure many of you could conjure up a more readable yet concise implementation.
Check it out (or not!):
Reference to the OG LC problem: https://leetcode.com/problems/accounts-merge/description/
Good luck on your phone screens & onsite loops.