Find All People With the Secret
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The data structure carrying this Google question is union-find, and the February 2026 report makes it clear the interviewers want to see you reset it correctly. You've got an OA coming and this one looks like plain graph spreading until the simultaneous-meeting rule bites. Sort meetings by time, group equal timestamps, and merge people inside each group. The catch is undoing unions for people who never got the secret. If you blank on that part, StealthCoder runs invisibly on your screen during the live OA and hands you the reset logic as a safety net.
The problem
There are n people numbered from 0 to n - 1. Initially, person 0 shares a secret with firstPerson at time 0. Each meeting is [x, y, time]. If either participant knows the secret at that time, both know it after the meeting. All meetings with the same timestamp happen simultaneously: knowledge may travel through an entire connected component formed by meetings at that timestamp, but it must not leak to a component that had no informed member when that timestamp began. Return every person who knows the secret after all meetings, in ascending order. Function findAllPeople(n: int, meetings: int[][], firstPerson: int) → int[] Examples Example 1 n = 6 meetings = [[1,2,5],[2,3,8],[1,5,10]] firstPerson = 1 return = [0,1,2,3,5] People 0 and 1 start informed. Person 2 learns at time 5, person 3 at time 8, and person 5 at time 10. Example 2 n = 6 meetings = [[1,2,5],[2,3,5],[4,5,5]] firstPerson = 1 return = [0,1,2,3] At time 5, the informed person 1 spreads the secret through the simultaneous chain 1-2-3. The separate component 4-5 remains uninformed. Constraints 2 <= n <= 100000 1 <= meetings.length <= 100000 Every meeting is [x, y, time] with 0 <= x, y < n, x != y, and 1 <= time <= 1000000000. 1 <= firstPerson < n. Duplicate meetings are allowed.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Sort meetings by time. Process each timestamp group on its own. Start with a union-find where 0 and firstPerson are joined. For a group, union x and y for every meeting. After the group, check each person involved: if their root is not connected to person 0, reset them to be their own parent. That undoes the false links from components that never learned the secret. The pitfall is skipping the reset, which leaks the secret through a later meeting via a stale union. Another pitfall is running BFS per timestamp with a global visited set, which breaks on same-time chains. Complexity is O(m log m) for sorting plus near-linear union-find work. Only reset people touched in the current group, not all n, or you'll blow up to O(n*m). If you freeze on the reset step during the live OA, StealthCoder is the hedge that shows the pattern.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Find All People With the Secret cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Google's OA.
Google reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Find All People With the Secret FAQ
What's the trick in Find All People With the Secret?+
Group meetings by timestamp and use union-find inside each group. After the group, reset anyone whose component isn't connected to person 0. That stops the secret from leaking through unions that never had an informed member at that time.
Why can't I just run one BFS over all meetings sorted by time?+
Meetings at the same time happen simultaneously, so the secret can chain through several of them in any order. A single pass in sorted order can miss those chains. You need to resolve whole timestamp groups as connected components, not meeting by meeting.
How hard is this really for a Google OA?+
It's a hard-leaning medium. The idea is short, but the reset step is easy to forget and hard to debug. If you've written union-find before, you can code it in 20 minutes. The sort plus grouping plus reset is the whole solution.
Do I need to reset the whole union-find after each timestamp?+
No. Only reset the people who appeared in meetings at that timestamp. Resetting all n people each time costs too much with 100000 meetings and would time out. Track the touched people in the group and reset only those who aren't connected to 0.
How do I prepare for this in 48 hours?+
Write union-find with path compression from memory. Then solve this problem once end to end, including the reset. Test with Example 2, where 4-5 must stay uninformed. Also test duplicate meetings and a chain of same-time meetings. That covers the failure cases.