155. Earliest Moment When Everyone Become Friends

Given an array logs, where logs[i] = [timestamp, x, y] means that at time timestamp people x and y became friends. Return the earliest moment when all n people are connected through a friendship chain, or -1.
Example 1
Input: logs = [[0,2,0],[1,0,1]], n = 4
Output: 3
Explanation: Early union with four people.
Example 2
Input: logs = [[20190101,0,1],[20190104,3,4]], n = 6
Output: 20190301
Explanation: All six people are connected by this time.
graph
JavaScript
Loading...
Line 1, Char 1