Skip to content
Discussion options

You must be logged in to vote

We need to efficiently track how the secret spreads through meetings over time, accounting for the fact that meetings at the same time can propagate the secret through multiple hops instantaneously.

Approach

We can solve this using a union-find (disjoint set) data structure with time-aware connections. The key insight is that:

  1. People who meet at the same time should be connected if at least one of them knows the secret
  2. Connections between people should be reset after processing each time slot (since people don't remain connected across different times)

Let's implement this solution in PHP: 2092. Find All People With Secret

<?php
/**
 * @param Integer $n
 * @param Integer[][] $meetings

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz Dec 19, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Dec 19, 2025
Maintainer Author

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested hard Difficulty
2 participants