The Earliest Moment When Everyone Become Friends

Medium · Graphs · about 20 minutes

Asked at Google, Uber, Amazon, Meta.

There are n people 0..n-1. logs[i] = [timestamp, x, y] means x and y become friends at timestamp. Friendship is transitive for acquaintance: if a knows b and b knows c, then a is acquainted with c. Return the earliest time at which everyone is acquainted with everyone else, or -1 if it never happens.

Related guides