Find All People With Secret
candidate master · 1465 · lc hard +32 · verified · 48.4% accepted · 1,943 likes · top 34%
Description
You are given an integer n indicating there are n people numbered from 0 to n - 1. You are also given a 0-indexed 2D integer array meetings where meetings[i] = [xi, yi, timei] indicates that person xi and person yi have a meeting at timei. A person may attend multiple meetings at the same time. Finally, you are given an integer firstPerson.
Person 0 holds a secret and shares it with firstPerson at time 0. Whenever a meeting occurs and at least one participant already knows the secret, the other participant learns it too. Sharing happens instantly, so a person who learns the secret at time t can share it with others in meetings also occurring at time t.
Return a list of all people who know the secret once all meetings have concluded. The answer may be returned in any order.
Example 1:
Example 2:
Example 3:
Code