FastPrepMost Active Caller by Distinct Contacts
Problems/Most Active Caller by Distinct Contacts

Most Active Caller by Distinct Contacts

Google logoGoogle● EasyINTERNFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The firsthand Shanghai Intern report asks for the most active user by number of different users contacted, independent of message count. Undirected contact counting, self-calls, empty input, bounds, and the tie rule were not preserved; the judged core task matches the visible source at about 90%.

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[][]) → String

Examples

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 calls is at most 2 * 10^6.

More Google problems

  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public String mostActiveCaller(String[][] calls) {
        // Write your code here.
    }
}
Checking account…