The Earliest Moment When Everyone Become Friends
Difficulty: Medium
Category: DSA
Topics: Array, Union Find, Sorting
Asked at: Google
You are given an integer `n` representing the number of people in a social group, labeled from `0` to `n - 1`. You are also given a list of logs `logs`, where each `logs[i] = [timestamp, x, y]` indicates that person `x` and person `y` became friends at time `timestamp`.
Friendship is **transitive**: if person `a` is a friend of person `b`, and person `b` is a friend of person `c`, then person `a` is also a friend of person `c`. A group of people are considered to be **all friends** if every pair of people are directly or indirectly friends.
Return _the earliest timestamp at which everyone in the group became friends_. If there is no such moment, return `-1`.
**Constraints:**
- `n ==` number of people in the group, `1 <= n <= 100`
- `1 <= logs.length <= 10^4`
- `logs[i].length == 3`
- `0 <= timestamp <= 10^9`
- `0 <= x, y <= n - 1`
- `x != y`
- All `timestamp` values in `logs` are not necessarily in order
**Note:** If multiple events happen at the same timestamp, they can occur in any order.