1101. The Earliest Moment When Everyone Become Friends
In a social group, there are N
people, with unique integer ids from 0
to N-1
.
We have a list of logs
, where each logs[i] = [timestamp, id_A, id_B]
contains a non-negative integer timestamp, and the ids of two different people.
Each log represents the time in which two different people became friends. Friendship is symmetric: if A is friends with B, then B is friends with A.
Let's say that person A is acquainted with person B if A is friends with B, or A is a friend of someone acquainted with B.
Return the earliest time for which every person became acquainted with every other person. Return -1 if there is no such earliest time.
Example 1:
Note:
2 <= N <= 100
1 <= logs.length <= 10^4
0 <= logs[i][0] <= 10^9
0 <= logs[i][1], logs[i][2] <= N - 1
It's guaranteed that all timestamps in
logs[i][0]
are different.logs
are not necessarily ordered by some criteria.logs[i][1] != logs[i][2]
Last updated
Was this helpful?