Earliest Moment Every Teams User Joins One Connected Network
Last updated: November 29, 2026
Quick Overview
Given a log of (timestamp, user_a, user_b) events meaning two Teams users started a chat, and n users labeled 0..n-1, return the earliest timestamp after which every user is connected to every other through some chain of chats, or -1 if that never happens.
Microsoft
November 29, 20260
0
0 solved
Given a log of (timestamp, user_a, user_b) events meaning two Teams users started a chat, and n users labeled 0..n-1, return the earliest timestamp after which every user is connected to every other through some chain of chats, or -1 if that never happens.
A union find question in the style of Microsoft onsites, framed around Teams collaboration graphs. The interviewer checks that you sort by time, track the component count as unions succeed, and stop as soon as it reaches one.
What the Interviewer Expects
- Sort events by timestamp
- Union users and decrement the component count on successful merges
- Return the timestamp when the count reaches one
- Return -1 if it never does
- Explain why union find beats repeated BFS
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
- How would you answer many queries asking whether two users were connected at time t?
- What if chats can also end and connections break?
- How would you return the size of the largest group over time?
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: n and a list of (t, a, b) events, not necessarily sorted. Output: smallest t at which all n users are in one component, or -1. With n = 1 the single user is connected from the start, so r...
High-Level Design
Sort events by timestamp. Start with components = n. For each event, attempt union(a, b); if it merges two different sets, decrement components. The moment components hits 1, return the curren...