As reported: Amazon SDE-2 loop (Bangalore, June 2025), round 4 — bar raiser / problem solving, after 30 minutes of Leadership Principles:
npeople, friendship logs[timestamp, x, y], friendship is transitive, millions of data points — find the earliest time at which everyone is friends with everyone. A disjoint-set (union–find) solution was the intended one.
There are n people labelled 0 … n−1. logs[i] = [timestamp_i, x_i, y_i] means x_i and y_i become friends at time timestamp_i. Friendship is symmetric and transitive: if a is friends with b and b with c, then a is acquainted with c. Return the earliest time at which every person is acquainted with every other person, or -1 if that never happens.
This is LeetCode 1101 — The Earliest Moment When Everyone Become Friends.
Example 1
logs = [[20190101,0,1],[20190104,3,4],[20190107,2,3],[20190211,1,5],
[20190224,2,4],[20190301,0,3],[20190312,1,2],[20190322,4,5]]
n = 6
Output: 20190301
Example 2
logs = [[0,2,0],[1,0,1],[3,0,3],[4,1,2],[7,3,1]]
n = 4
Output: 3
Constraints: 2 ≤ n ≤ 100; 1 ≤ logs.length ≤ 10⁴; all timestamps are unique; x_i ≠ y_i. (The interview version stressed millions of log entries — the same algorithm applies.)
Code runner format: one JSON value per line, in order: logs, n (LeetCode's test-case format). Implement earliestAcq(logs, n); the harness prints the time.