Given a log of lines ' A became friend to B', return the earliest timestamp at which everyone is connected (friends transitively).
Asked in the Coding round 1 stage. Implement earliest_connected_timestamp(logs). Each log line is a string such as "12 Alice became friend to Bob"; timestamps are integers, and the log may not be ordered. Consider every person appearing in the logs. Return -1 if all people never become connected.
Examples: ['1 A became friend to B', '3 B became friend to C'] returns 3; ['5 A became friend to B', '2 B became friend to C'] returns 5 after timestamp ordering.
Constraints: There can be zero or more lines, each line has the stated format, and the two people on a line are distinct.
def earliest_connected_timestamp(logs):