Find All People With the Secret
Updated
Problem statement
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) → List<Integer>Examples
Example 1
n = 6meetings = [[1,2,5],[2,3,8],[1,5,10]]firstPerson = 1return = [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 = 6meetings = [[1,2,5],[2,3,5],[4,5,5]]firstPerson = 1return = [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 <= 1000001 <= meetings.length <= 100000- Every meeting is
[x, y, time]with0 <= x, y < n,x != y, and1 <= time <= 1000000000. 1 <= firstPerson < n.- Duplicate meetings are allowed.
More Google Phone Screen questions
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Logger Rate Limiter with Every-Arrival HistoryPHONE SCREEN · Seen Nov 2026
- Minimum Total Layover WaitPHONE SCREEN · Seen Nov 2026
- Reach a Destination Through Scheduled FlightsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Find All People With SecretIDFC Bank · ONSITE INTERVIEWIDFC Bank interview questions
- Find All People with the SecretAmazon · PHONE SCREEN
- Contact Tracing Through Timed MeetingsHudson River Trading · PHONE SCREENHudson River Trading interview questions
- Record Linkage Part 3 - Full Connected ComponentStripe · PHONE SCREENStripe interview questions
- Evaluate DivisionApple · PHONE SCREENApple interview questions
- Count Friend CirclesOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Path Existence in an Undirected GraphByteDance · PHONE SCREENByteDance interview questions
- Number of ProvincesSambaNova Systems · PHONE SCREENSambaNova Systems interview questions
- Terminal Nodes for Each SourceIndeed · PHONE SCREENIndeed interview questions
- Delivery Management SystemAkuna Capital · OAAkuna Capital interview questions