Most Active Caller by Distinct Contacts
Problem statement
You are given call records in calls. Each row has four strings in this order: [timestamp, sender, receiver, message].
Two different users are contacts when at least one record has one as the sender and the other as the receiver. Repeated messages between the same pair count only once for both users. A self-call does not add a contact.
Return the user with the greatest number of distinct contacts. If several users tie, return the lexicographically smallest user ID. Return the empty string when there are no records.
Function
mostActiveCaller(calls: String[][]) → StringExamples
Example 1
calls = [["09:00","Ada","Bob","hi"],["09:05","Ada","Cara","status"],["09:10","Bob","Cara","ok"],["09:15","Ada","Drew","done"],["09:20","Bob","Ada","again"]]return = "Ada"Ada has three distinct contacts: Bob, Cara, and Drew. The repeated Ada-Bob conversation still contributes one contact.
Example 2
calls = [["1","zoe","amy","x"],["2","bob","cara","y"],["3","amy","bob","z"]]return = "amy"Amy and Bob each have two distinct contacts. Amy is lexicographically smaller, so she is returned.
Example 3
calls = []return = ""There are no users in an empty call log.
Constraints
0 <= calls.length <= 200000.- Every row contains exactly four non-null strings.
- Sender and receiver IDs are non-empty.
- The combined number of characters in
callsis at most2 * 10^6.