Earliest Time All Users Are Connected
You are given a list of users and a list of ride-share log entries. Each log entry records a timestamp and two users who shared a ride. Once two users share a ride, they are considered connected. Connectivity is transitive: if A is connected to B and B is connected to C, then A is connected to C.
Each log entry is formatted as "timestamp userA userB", where timestamp is an integer. Process the logs in increasing timestamp order and return the earliest timestamp when all users are connected. If the users never all become connected, return -1.
Complete the function earliestFullConnection in the editor.
earliestFullConnection has the following parameters:
String users[]: all users in the systemString logs[]: ride-share connection logs
Returns
int: the earliest timestamp when all users are connected, or -1 if this never happens
1Example 1
2Example 2
3Example 3
Constraints
Limits and guarantees your solution can rely on.
- Each log entry has the format
"timestamp userA userB". - Logs may be provided out of timestamp order.
- User names in logs are included in
users.