Question
A social network has n people labeled 0..n-1, all initially strangers. You get logs where each log is [timestamp, a, b] meaning a and b became acquainted at that timestamp; acquaintance is mutual and transitive (friends of friends are connected). Return the earliest timestamp at which every person is connected to every other person (directly or transitively). If they never all become connected, return -1. With only one person (n = 1) there is no one to connect to, so return -1. Timestamps are non-negative integers and may be unsorted.
earliest_all_connected(n: int, logs: list[list[int]]) → int[4,[[20,0,1],[5,2,3],[10,1,2],[30,0,3]]]out20State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.