Back to problems

The Earliest Moment When Everyone Become Friends

Algorithm · Uber · Medium

There are n individuals numbered from 0 through n - 1. You receive a list named logs, with each entry formatted as: Such an entry records that people a and b form a friendship at timestamp. Connections are transitive: when a is linked with b and b is linked with c, all three belong to one friendship group. Determine the smallest timestamp at which all n people are connected. Return -1 when no timestamp produces a single connected group. Input Format The opening line provides…

Checking your access…