Answer Same-Organization Queries While Business Account Merges Stream In
Last updated: November 29, 2026
Quick Overview
You process a stream of operations on n business accounts: ('merge', a, b) combines the organizations containing a and b, and ('same', a, b) asks whether a and b currently belong to the same organization. Return the answers to every 'same' query in order.
Meta
November 29, 20260
0
0 solved
You process a stream of operations on n business accounts: ('merge', a, b) combines the organizations containing a and b, and ('same', a, b) asks whether a and b currently belong to the same organization. Return the answers to every 'same' query in order.
A Meta phone screen style question that introduces union find through Business Manager, where ad accounts and pages get consolidated under one business over time. The interviewer is checking a clean disjoint set implementation with path compression and union by size, and that you can explain the near-constant amortized cost.
What the Interviewer Expects
- Implement find with path compression
- Implement union by size or rank
- Answer each query in near O(1) amortized time
- Explain why BFS per query is too slow for a long stream
- Handle merging two accounts already in the same org
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- What is the inverse Ackermann function and why does it appear here?
- How would you support splitting an organization apart?
- How would you shard this structure if there are billions of accounts?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input:
naccounts0..n-1andops, a list of tuples('merge', a, b)or('same', a, b). - Output: list of booleans for the
'same'operations. - The stream can be long (millions of ops), so...
High-Level Design
Merges only ever combine groups and never split them, which is exactly the setting for a disjoint set union.
parent[x]points toward the representative ofx's group.find(x)follows parents...