1085. The Earliest Moment When Everyone Become Friends

Medium
Array
Union Find
Sorting

Description

Hints

Hint 1
Sort the log items by their timestamp.
Hint 2
How can we model this problem as a graph problem?
Hint 3
Let's use a union-find data structure. At the beginning we have a graph with N nodes but no edges.
Hint 4
Then we loop through the events and unite each node until the number of connected components reach to 1. Notice that each time two different connected components are united the number of connected components decreases by 1.

Similar Questions

Statistics

Acceptance
65.8%
Submissions
194,464
Accepted
128,009