bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 1101. The Earliest Moment When Everyone Become Friends

1101. The Earliest Moment When Everyone Become Friends

Leetcode Solutions

Union-Find (Disjoint-Set) Approach

  1. Sort the logs by their timestamps.
  2. Initialize the Union-Find data structure with n elements, each in its own set.
  3. Iterate over the sorted logs.
  4. For each log, use the union operation to merge the sets containing the two individuals.
  5. If the union operation actually merges two sets, decrement the count of disjoint sets.
  6. Once the count of disjoint sets is 1, return the timestamp of the current log.
  7. If the end of the logs is reached and the count of disjoint sets is greater than 1, return -1.
UML Thumbnail

Breadth-First Search (BFS) Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...