Tap here to switch tabs
Problem
Submissions

Problem: The Earliest Moment When Everyone Become Friends

med
30 min
Try to solve the The Earliest Moment When Everyone Become Friends problem.

Statement

There are n people numbered from 00 to n −1- 1. You are given a array logs where each element logs[i] =[= [timestamp_i$, ‘xi‘`x_i`, ‘yi‘`y_i`]$ represents a friendship established between person x_i and person y_i at the given timestamp_i.

Friendship is symmetric and transitive. This means that if person AA is friends with person BB, then person BB is friends with person AA. Furthermore, if person AA is friends with person BB and person BB is friends with person CC, then person AA is indirectly friends with person CC.

Return the earliest timestamp at which every person in the group becomes friends with everyone else. If it is impossible for all n people to become connected, return −1-1.

Constraints:

  • 2≤2 \leq n ≤100\leq 100

  • 1≤1 \leq logs.length ≤104\leq 10^4

  • logs[i].length =3= 3

  • 0≤0 \leq timestamp_i ≤109\leq 10^9

  • 0≤0 \leq x_i, y_i ≤\leq n −1- 1

  • x_i ≠\neq y_i

  • All values of timestamp_i are unique.

  • All pairs (x_i, y_i) occur at most once in the input.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: The Earliest Moment When Everyone Become Friends

med
30 min
Try to solve the The Earliest Moment When Everyone Become Friends problem.

Statement

There are n people numbered from 00 to n −1- 1. You are given a array logs where each element logs[i] =[= [timestamp_i$, ‘xi‘`x_i`, ‘yi‘`y_i`]$ represents a friendship established between person x_i and person y_i at the given timestamp_i.

Friendship is symmetric and transitive. This means that if person AA is friends with person BB, then person BB is friends with person AA. Furthermore, if person AA is friends with person BB and person BB is friends with person CC, then person AA is indirectly friends with person CC.

Return the earliest timestamp at which every person in the group becomes friends with everyone else. If it is impossible for all n people to become connected, return −1-1.

Constraints:

  • 2≤2 \leq n ≤100\leq 100

  • 1≤1 \leq logs.length ≤104\leq 10^4

  • logs[i].length =3= 3

  • 0≤0 \leq timestamp_i ≤109\leq 10^9

  • 0≤0 \leq x_i, y_i ≤\leq n −1- 1

  • x_i ≠\neq y_i

  • All values of timestamp_i are unique.

  • All pairs (x_i, y_i) occur at most once in the input.