Meta Variant for Accounts Merge (LC721)
3123
Feb 27, 2025
May 10, 2025

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:

  • What if the input changes to be a map from an ID to its corresponding emails?

Please note there are situations where you’ll have to come up with the input yourself, so it may be a bit more flexible.

  • What if the output is expected to be a 2D list where each list is a group of all of the same IDs (that have the same emails)?

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!):

Leetcode 721 Accounts Merge (Link)


Reference to the OG LC problem: https://leetcode.com/problems/accounts-merge/description/

Good luck on your phone screens & onsite loops.

Comments (4)