The Find All People With Secret interview question is a complex connectivity problem. You start with person 0 sharing a secret with person firstPerson at time 0. You are then given a list of meetings [person1, person2, time]. If someone who knows the secret meets someone else at a specific time, the secret is shared. A key rule is that secrets can spread instantaneously among everyone meeting at the same time. You need to return a list of everyone who knows the secret after all meetings.
This "Hard" problem is asked by Google, Microsoft, and Amazon to evaluate a candidate's mastery of graph theory and time-ordered processing. It tests the ability to handle Graph interview patterns where the graph structure changes over time. It evaluation your proficiency with Union Find or BFS/DFS and your ability to correctly group events by timestamps.
This problem is best solved using Union Find with Reset or BFS per Timestamp.
find to spread the secret to everyone in their connected components.Meetings: [[1, 2, 5], [2, 3, 5], [3, 4, 10]]. Initial secret: {0, 1}.
When dealing with "dynamic connectivity" (connections that only exist at certain times), always process events in time buckets. Union Find is great for this, but remember to "undo" connections that didn't lead to a secret-sharing event.