Hi👋SpeedAlgo • Deliberate Practice & Cognitive Ergonomics for Software Engineers

An interactive algorithm mastery and technical interview preparation platform published by Hi👋WebEnterprise. Built for senior and staff software engineers preparing for rigorous coding screens at top tech companies (FAANG/MAMAA).

13 Core Algorithmic Patterns & 225 Practice Problems

  • 1. Two Pointers (16 Paradigms, 43 Problems): Opposite ends, sorted pair sums, palindrome verification, trapping rain water, 3Sum, container with most water — includes the Sliding Window and Fast & Slow Pointers paradigms (contiguous subarray invariants, longest substrings, Floyd's cycle detection, linked list middle).
  • 2. Binary Search (9 Paradigms, 14 Problems): Monotonic predicate partitioning (feasible(x)), boundary search, rotated sorted arrays, square roots, minimum ship capacity, median of two sorted arrays, matrix median on value range.
  • 3. Bit Manipulation (5 Paradigms, 11 Problems): Counting set bits, XOR cancellation, bit reversal, bitmask pairing, maximum XOR with a bitwise trie.
  • 4. Math & Geometry (8 Paradigms, 14 Problems): Sieve of Eratosthenes, integer/roman conversions, modular arithmetic, geometric simulation.
  • 5. Tree/Graph Depth-First Search (15 Paradigms, 24 Problems): Path sums, lowest common ancestor, tree diameter, validating BSTs, tree DP (House Robber III, Binary Tree Cameras).
  • 6. Tree/Graph Breadth-First Search (5 Paradigms, 12 Problems): Level-order traversals, shortest path in unweighted graphs, zig-zag traversals, rotting oranges, word ladders.
  • 7. Graphs (12 Paradigms, 22 Problems): Topological sort, cycle detection, Dijkstra's algorithm, bipartite graph validation, network delay.
  • 8. Backtracking (6 Paradigms, 14 Problems): Subsets, permutations, combinations, constraint satisfaction, pruning, N-Queens, Sudoku solver.
  • 9. Dynamic Programming (13 Paradigms, 28 Problems): Memoization vs tabulation, 0/1 knapsack, unbounded knapsack, coin change, edit distance, longest common subsequence.
  • 10. Heap / Priority Queue (9 Paradigms, 11 Problems): Running medians, top-k elements, interval scheduling, IPO, k-way merges.
  • 11. Advanced Data Structures (7 Paradigms, 17 Problems): Trie (prefix tree), Union-Find (Disjoint Set Union), LRU Cache, LFU Cache, range-sum queries with updates.
  • 12. Stack (5 Paradigms, 9 Problems): Next greater element, largest rectangle in histogram, remove k digits, decode string, min stack.
  • 13. Intervals & Greedy (2 Paradigms, 6 Problems): Merge intervals, interval scheduling, meeting rooms by sweep line, jump game.

4-Stage Deliberate Practice Framework

  1. Stage 1 (Compare & Learn): Read the pattern's mental model, loop invariant and Big-O proof, compare the pattern's template with the problem's solution side by side, and use the step-by-step debugger. The solution can also be shown in C#, Java, TypeScript, C++, Go or Rust for almost every problem.
  2. Stage 2 (Active Recall): Rebuild the solution from memory in a code editor, with an invariant checklist and optional progressive hints, and check it against a judged test suite.
  3. Stage 3 (AI Interview Coach, coming soon): A mock-interview stage still in development; for now, students go straight from Stage 2 to Stage 4.
  4. Stage 4 (Solve on Your Own): Solve a new problem on your own against a 15-minute timer; your code is graded against a test suite. Python and TypeScript run in your browser and C# runs on our server (design problems grade in Python and TypeScript).

Equipped with a spaced-repetition review hub on a fixed 7-step schedule (1 day up to 90 days), a two-pane Studio workspace, and study notes.

Pricing, Access & Commercial Terms

  • Core Curriculum: 100% Free. No credit card required.
  • Coins: New accounts get 40 free coins once, the daily claim adds +20 coins once a day, and inviting a friend earns you +25 coins when they complete their first practice step. These are the only ways to earn coins.
  • AI Coach: Each AI coach question costs 1-5 coins, priced by the server according to its size.
  • BYOK (Bring Your Own Key): AI coaching is free with your own Google Gemini, OpenAI or OpenRouter API key (BYOK).
  • Extras: Coins also unlock extras for 24 hours: a Recall hint level (1 coin), a Solve solution reveal (2), a LeetCode problem card's solutions (1) and a pattern's extra canonical problems (1).
  • Payments & Refunds: Nothing on the site is sold for money: coins can only be earned, never bought. There are no subscriptions or charges, so there is nothing to refund.
  • Platform Operator: Hi👋WebEnterprise. Support & policies at hispeedalgo.com.
Skip to main content
Hi👋SpeedAlgo

Invariant-First Algorithmic Mastery

Arena
238Items
Theory Context•Advanced Data Structures
MediumLC 721

Accounts Merge (LeetCode 721)

Target Frequency:MetaAppleAmazon

You're given accounts, a list where each entry is [name, email1, email2, ...] -- one person's name followed by every email on that account.

Merge accounts that belong to the same real person: two accounts are the same person whenever they share at least one email, even transitively through a chain of shared emails. Two accounts with the same name are NOT automatically the same person -- only a shared email proves that -- and one person may hold several accounts, all under their one name.

Return the merged accounts, each as [name, ...emails sorted ascending]; the accounts themselves can come back in any order.

Worked Examples

Example 1
Input:accounts = [["John","johnsmith@mail.com","john_newyork@mail.com"],["John","johnsmith@mail.com","john00@mail.com"],["Mary","mary@mail.com"],["John","johnnybravo@mail.com"]]
Output:[["John","john00@mail.com","john_newyork@mail.com","johnsmith@mail.com"],["Mary","mary@mail.com"],["John","johnnybravo@mail.com"]]
Explanation: The first two John accounts share "johnsmith@mail.com", so they merge into one person. The third John and Mary share no email with anyone else, so each stays its own account. Any ordering of the three merged accounts is valid, so e.g. Mary first, then the lone John, then merged John would also be accepted.
Example 2
Input:accounts = [["Gabe","Gabe0@m.co","Gabe3@m.co","Gabe1@m.co"],["Kevin","Kevin3@m.co","Kevin5@m.co","Kevin0@m.co"],["Ethan","Ethan5@m.co","Ethan4@m.co","Ethan0@m.co"],["Hanzo","Hanzo3@m.co","Hanzo1@m.co","Hanzo0@m.co"],["Fern","Fern5@m.co","Fern1@m.co","Fern0@m.co"]]
Output:[["Ethan","Ethan0@m.co","Ethan4@m.co","Ethan5@m.co"],["Gabe","Gabe0@m.co","Gabe1@m.co","Gabe3@m.co"],["Hanzo","Hanzo0@m.co","Hanzo1@m.co","Hanzo3@m.co"],["Kevin","Kevin0@m.co","Kevin3@m.co","Kevin5@m.co"],["Fern","Fern0@m.co","Fern1@m.co","Fern5@m.co"]]
Explanation: No two accounts share an email, so nothing merges; each account just gets its emails sorted.

⚖️Formal Constraints & Bounds

  • 1 <= accounts.length <= 1000

  • 2 <= accounts[i].length <= 10

  • 1 <= accounts[i][j].length <= 30

  • accounts[i][0] consists of English letters.

  • accounts[i][j] (for j > 0) is a valid email.

Deep-Dive & Conceptual Insights

Core Insight

DSU transitivity clusters overlapping identity records without explicit adjacency list graphs.

Real-World Scenario & Production Applications

Identity resolution in customer data platforms (CDP), fraud detection entity resolution.

Step-by-Step Execution Trace Table

AccountEmailsUnion ActionCanonical Root
John 1'johnsmith', 'john_newyork'union('john_newyork', 'johnsmith')'johnsmith'
John 2'johnsmith', 'john00'union('john00', 'johnsmith')'johnsmith'
Mary'mary'self root'mary'
Code Shape
Archetype Code Shape
Python
1Map email -> parent and email -> owner
2Union all emails in each account to account's first email
3Group by find(email), sort emails, return [owner] + sorted_emails

Conceptual Narrative

Multiple user accounts sharing a single email address belong to the same person. Treating emails as graph nodes and unifying secondary emails to the primary email clusters overlapping accounts in O(N log N) time.

🧭 Conceptual Foundation & Pattern Intuition

In Accounts Merge (LC 721), each account has a name and a list of email addresses. Two accounts belong to the same person if they share at least one common email. Notice that email overlap is transitive: if Account 1 shares an email with Account 2, and Account 2 shares an email with Account 3, all three accounts belong to the same human, even if Account 1 and Account 3 have no emails in common. This transitivity is the signature of Connected Components in an Equivalence Graph:

  • Each unique email address is a node in our DSU.
  • For each account with emails [e1,e2,…,ek][e_1, e_2, \dots, e_k][e1​,e2​,…,ek​], we union e2,…,eke_2, \dots, e_ke2​,…,ek​ to e1e_1e1​.
  • We record the owner's name for the canonical root email.
  • Finally, we group all emails by their canonical root find(email), sort each email group lexicographically, and prepend the owner's name.
🕵️ The Analogy: Unmasking Pseudonyms by Shared Contact Info

Imagine an investigator analyzing fraudulent bank accounts. Account A uses emails "john@gmail.com" and "john_work@corp.com". Account B uses "john_work@corp.com" and "john_vpn@anon.to". Even though Account A and Account B used different account IDs, the shared work email links them into a single identity ring. By pinning all emails to the first email seen on each application form, the investigator groups all aliases into unified dossiers.

🔑 Why It Works

The elegance of DSU is that we never build or traverse an explicit adjacency graph with BFS/DFS; the Disjoint Set automatically groups all transitively connected emails under their shared canonical parent.

  • Matching on account names: Two distinct people can share the same name (e.g. two different 'John's). Never union accounts solely by name; union strictly by shared email addresses.

  • All-pairs email union O(K2)O(K^2)O(K2): Unioning every email with every other email in an account takes quadratic time; unioning each email with the first email takes linear time.

  • Missing sorted output requirement: Forgetting to sort email lists alphabetically (sorted(emails)) before returning violates LC 721 output specification.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

Identity resolution / merging records that share overlapping identifiers.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: emails belonging to the same person share a canonical DSU root.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

This problem's traps are in Common Pitfalls above.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I map each email to its owner name and initialize its DSU parent. For each account, I union all subsequent emails to the account's first email union(first_email, email). I group all emails by their canonical root find(email) and return each group with the owner name and sorted emails. Runs in O(N · K log(NK)) time and O(N · K) space."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(A · K · alpha(N) + A · K log(A · K))

Look at the execution steps: Let A be number of accounts and K be max emails per account. Maps emails to account IDs and unions shared emails in O(A · K · alpha(N)). Sorting emails per component takes O(A · K log(A · K)). Total O(A · K log(A · K)).

SPACE COMPLEXITY

O(A · K) Auxiliary

Look at memory allocations: parent, rank and owner hold one entry per distinct email, and groups lists every email once: O(A · K) for A accounts of up to K emails. find calls itself once per level of a tree, and union by rank keeps every tree at most log2(A · K) + 1 levels tall, so the call stack is O(log(A · K)).

Formal Recurrence Relation

T(A, K) = O(A · K · α(N)) + O(A · K log(A · K))

Derivation Progression

Email-to-ID Union

union(first_email, e)

Links all emails in same account in DSU in O(A · K · alpha(N)).

Component Aggregation

groups[find(e)].append(e)

Groups emails by representative root in O(A · K).

Lexicographical Sort

∑ |Gi| log |Gi| ≤ O(A · K log(A · K))

Sorts emails per merged account.

Variable Definitions

AAA

Total number of account objects

KKK

Maximum number of email addresses per account

α(N)α(N)α(N)

Inverse Ackermann function (α ≤ 4)

Memory Architecture & Bounds

🟣 Call Stack

O(log(A · K)) Recursive find, union by rank

🔵 Auxiliary Heap

O(A · K) DSU parent map and email lookup dictionaries

🟢 Output Space

O(A · K) Merged account list

Boundary Best / Worst Cases

Best Case

O(A⋅Klog⁡K)O(A · K \log K)O(A⋅KlogK)

Average Case

O(A⋅Klog⁡(A⋅K))O(A · K \log(A · K))O(A⋅Klog(A⋅K))

Worst Case

O(A⋅Klog⁡(A⋅K))O(A · K \log(A · K))O(A⋅Klog(A⋅K))

Recurrence Tree Topology

Recurrence Tree Topology
Synthesizing vector architecture diagram...
Staff+ Engineering Perspective

Senior SWE Deconstruction & Hardware Caveats

ARCHITECTURAL SIGNALS & INTERVIEW TRIGGERS

Triggers: "merge accounts if they share an email", "person can have multiple accounts with same name". Multi-identity equivalence clustering: union accounts that share common identifiers. A Senior SWE maps each email to an account index, and unions account IDs directly in a DSU.

CONSTRAINTS & BOUNDS

N≤1000N \le 1000N≤1000 accounts, each with ≤10\le 10≤10 emails. Total emails ≤104\le 10^4≤104. Budget O(Eα(N)+Elog⁡E)O(E \alpha(N) + E \log E)O(Eα(N)+ElogE) sorting.

FAANG PRODUCTION TRAPS & EDGE CASES

Accounts sharing the same name but with completely disjoint emails represent different people and MUST remain separate. Emails in each merged account must be sorted lexicographically.

Theory Context•Advanced Data Structures
MediumLC 721

Accounts Merge (LeetCode 721)

Target Frequency:MetaAppleAmazon

You're given accounts, a list where each entry is [name, email1, email2, ...] -- one person's name followed by every email on that account.

Merge accounts that belong to the same real person: two accounts are the same person whenever they share at least one email, even transitively through a chain of shared emails. Two accounts with the same name are NOT automatically the same person -- only a shared email proves that -- and one person may hold several accounts, all under their one name.

Return the merged accounts, each as [name, ...emails sorted ascending]; the accounts themselves can come back in any order.

Worked Examples

Example 1
Input:accounts = [["John","johnsmith@mail.com","john_newyork@mail.com"],["John","johnsmith@mail.com","john00@mail.com"],["Mary","mary@mail.com"],["John","johnnybravo@mail.com"]]
Output:[["John","john00@mail.com","john_newyork@mail.com","johnsmith@mail.com"],["Mary","mary@mail.com"],["John","johnnybravo@mail.com"]]
Explanation: The first two John accounts share "johnsmith@mail.com", so they merge into one person. The third John and Mary share no email with anyone else, so each stays its own account. Any ordering of the three merged accounts is valid, so e.g. Mary first, then the lone John, then merged John would also be accepted.
Example 2
Input:accounts = [["Gabe","Gabe0@m.co","Gabe3@m.co","Gabe1@m.co"],["Kevin","Kevin3@m.co","Kevin5@m.co","Kevin0@m.co"],["Ethan","Ethan5@m.co","Ethan4@m.co","Ethan0@m.co"],["Hanzo","Hanzo3@m.co","Hanzo1@m.co","Hanzo0@m.co"],["Fern","Fern5@m.co","Fern1@m.co","Fern0@m.co"]]
Output:[["Ethan","Ethan0@m.co","Ethan4@m.co","Ethan5@m.co"],["Gabe","Gabe0@m.co","Gabe1@m.co","Gabe3@m.co"],["Hanzo","Hanzo0@m.co","Hanzo1@m.co","Hanzo3@m.co"],["Kevin","Kevin0@m.co","Kevin3@m.co","Kevin5@m.co"],["Fern","Fern0@m.co","Fern1@m.co","Fern5@m.co"]]
Explanation: No two accounts share an email, so nothing merges; each account just gets its emails sorted.

⚖️Formal Constraints & Bounds

  • 1 <= accounts.length <= 1000

  • 2 <= accounts[i].length <= 10

  • 1 <= accounts[i][j].length <= 30

  • accounts[i][0] consists of English letters.

  • accounts[i][j] (for j > 0) is a valid email.

Deep-Dive & Conceptual Insights

Core Insight

DSU transitivity clusters overlapping identity records without explicit adjacency list graphs.

Real-World Scenario & Production Applications

Identity resolution in customer data platforms (CDP), fraud detection entity resolution.

Step-by-Step Execution Trace Table

AccountEmailsUnion ActionCanonical Root
John 1'johnsmith', 'john_newyork'union('john_newyork', 'johnsmith')'johnsmith'
John 2'johnsmith', 'john00'union('john00', 'johnsmith')'johnsmith'
Mary'mary'self root'mary'
Code Shape
Archetype Code Shape
Python
1Map email -> parent and email -> owner
2Union all emails in each account to account's first email
3Group by find(email), sort emails, return [owner] + sorted_emails

Conceptual Narrative

Multiple user accounts sharing a single email address belong to the same person. Treating emails as graph nodes and unifying secondary emails to the primary email clusters overlapping accounts in O(N log N) time.

🧭 Conceptual Foundation & Pattern Intuition

In Accounts Merge (LC 721), each account has a name and a list of email addresses. Two accounts belong to the same person if they share at least one common email. Notice that email overlap is transitive: if Account 1 shares an email with Account 2, and Account 2 shares an email with Account 3, all three accounts belong to the same human, even if Account 1 and Account 3 have no emails in common. This transitivity is the signature of Connected Components in an Equivalence Graph:

  • Each unique email address is a node in our DSU.
  • For each account with emails [e1,e2,…,ek][e_1, e_2, \dots, e_k][e1​,e2​,…,ek​], we union e2,…,eke_2, \dots, e_ke2​,…,ek​ to e1e_1e1​.
  • We record the owner's name for the canonical root email.
  • Finally, we group all emails by their canonical root find(email), sort each email group lexicographically, and prepend the owner's name.
🕵️ The Analogy: Unmasking Pseudonyms by Shared Contact Info

Imagine an investigator analyzing fraudulent bank accounts. Account A uses emails "john@gmail.com" and "john_work@corp.com". Account B uses "john_work@corp.com" and "john_vpn@anon.to". Even though Account A and Account B used different account IDs, the shared work email links them into a single identity ring. By pinning all emails to the first email seen on each application form, the investigator groups all aliases into unified dossiers.

🔑 Why It Works

The elegance of DSU is that we never build or traverse an explicit adjacency graph with BFS/DFS; the Disjoint Set automatically groups all transitively connected emails under their shared canonical parent.

  • Matching on account names: Two distinct people can share the same name (e.g. two different 'John's). Never union accounts solely by name; union strictly by shared email addresses.

  • All-pairs email union O(K2)O(K^2)O(K2): Unioning every email with every other email in an account takes quadratic time; unioning each email with the first email takes linear time.

  • Missing sorted output requirement: Forgetting to sort email lists alphabetically (sorted(emails)) before returning violates LC 721 output specification.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

Identity resolution / merging records that share overlapping identifiers.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: emails belonging to the same person share a canonical DSU root.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

This problem's traps are in Common Pitfalls above.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I map each email to its owner name and initialize its DSU parent. For each account, I union all subsequent emails to the account's first email union(first_email, email). I group all emails by their canonical root find(email) and return each group with the owner name and sorted emails. Runs in O(N · K log(NK)) time and O(N · K) space."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(A · K · alpha(N) + A · K log(A · K))

Look at the execution steps: Let A be number of accounts and K be max emails per account. Maps emails to account IDs and unions shared emails in O(A · K · alpha(N)). Sorting emails per component takes O(A · K log(A · K)). Total O(A · K log(A · K)).

SPACE COMPLEXITY

O(A · K) Auxiliary

Look at memory allocations: parent, rank and owner hold one entry per distinct email, and groups lists every email once: O(A · K) for A accounts of up to K emails. find calls itself once per level of a tree, and union by rank keeps every tree at most log2(A · K) + 1 levels tall, so the call stack is O(log(A · K)).

Formal Recurrence Relation

T(A, K) = O(A · K · α(N)) + O(A · K log(A · K))

Derivation Progression

Email-to-ID Union

union(first_email, e)

Links all emails in same account in DSU in O(A · K · alpha(N)).

Component Aggregation

groups[find(e)].append(e)

Groups emails by representative root in O(A · K).

Lexicographical Sort

∑ |Gi| log |Gi| ≤ O(A · K log(A · K))

Sorts emails per merged account.

Variable Definitions

AAA

Total number of account objects

KKK

Maximum number of email addresses per account

α(N)α(N)α(N)

Inverse Ackermann function (α ≤ 4)

Memory Architecture & Bounds

🟣 Call Stack

O(log(A · K)) Recursive find, union by rank

🔵 Auxiliary Heap

O(A · K) DSU parent map and email lookup dictionaries

🟢 Output Space

O(A · K) Merged account list

Boundary Best / Worst Cases

Best Case

O(A⋅Klog⁡K)O(A · K \log K)O(A⋅KlogK)

Average Case

O(A⋅Klog⁡(A⋅K))O(A · K \log(A · K))O(A⋅Klog(A⋅K))

Worst Case

O(A⋅Klog⁡(A⋅K))O(A · K \log(A · K))O(A⋅Klog(A⋅K))

Recurrence Tree Topology

Recurrence Tree Topology
Synthesizing vector architecture diagram...
Staff+ Engineering Perspective

Senior SWE Deconstruction & Hardware Caveats

ARCHITECTURAL SIGNALS & INTERVIEW TRIGGERS

Triggers: "merge accounts if they share an email", "person can have multiple accounts with same name". Multi-identity equivalence clustering: union accounts that share common identifiers. A Senior SWE maps each email to an account index, and unions account IDs directly in a DSU.

CONSTRAINTS & BOUNDS

N≤1000N \le 1000N≤1000 accounts, each with ≤10\le 10≤10 emails. Total emails ≤104\le 10^4≤104. Budget O(Eα(N)+Elog⁡E)O(E \alpha(N) + E \log E)O(Eα(N)+ElogE) sorting.

FAANG PRODUCTION TRAPS & EDGE CASES

Accounts sharing the same name but with completely disjoint emails represent different people and MUST remain separate. Emails in each merged account must be sorted lexicographically.

© 2026 Hi👋WebEnterprise. All rights reserved.
Sitemap•llms.txt•