Spread a Leaked Secret Through Time-Ordered Meetings

Last updated: November 29, 2026

Quick Overview

Person 0 knows a secret and shares it with person first at time 0. Meetings (a, b, t) happen at time t, and anyone who knows the secret during a meeting shares it instantly, including within chains of meetings at the same time. Return everyone who knows the secret after all meetings.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Person 0 knows a secret and shares it with person first at time 0. Meetings (a, b, t) happen at time t, and anyone who knows the secret during a meeting shares it instantly, including within chains of meetings at the same time. Return everyone who knows the secret after all meetings.

Modeled on information propagation in a Google Meet or Chat graph, this onsite question is about union-find with rollback per time slot. The interviewer checks that you group meetings by time, union within the group, and then reset people who did not connect to the secret, since their connections must not carry forward.

What the Interviewer Expects
  • Sorts meetings by time and processes same-time meetings as one batch
  • Unions all pairs in a batch so chains propagate instantly
  • Resets batch participants not connected to the secret holder
  • Explains why stale unions would leak the secret incorrectly
  • Handles first being 0 or appearing in no meeting
Key Topics to Cover
Union-Find
Sorting
Grouping by Time
Rollback
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • What if sharing takes one time unit, so chains within a time slot do not propagate?
  • Return the time each person learned the secret.
  • How would BFS per time slot compare?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: n, list of [a, b, t], and first.
  • Within one timestamp, the secret flows across any chain of meetings.
  • Output: sorted list of people who know the secret....
High-Level Design

Sort meetings by time and process each timestamp as a batch. First union every pair in the batch. Then, for each participant not in the same set as person 0, reset their parent to themselves. That res...


Submit Your Answer
Markdown supported