Most Active Caller by Distinct Contacts
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Google's September 2026 OA hands you a call log and asks who talks to the most different people. Strip the story and it's an undirected graph where you count the degree of every node, with duplicates collapsed. That's a hash map of sets, plus a tie-break on the smallest ID. It looks like a database question wearing a coding costume. If you blank on the details, StealthCoder runs invisibly during the live OA and gives you a working solution as a safety net. Know the shape first, though.
The problem
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.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is treating contacts as symmetric. For each row, skip it if sender equals receiver. Otherwise add receiver to sender's set and sender to receiver's set. Sets handle the repeated-message dedupe for free, so Ada-Bob then Bob-Ada still counts once. Then scan the map, keep the user with the largest set size, and on a tie keep the lexicographically smaller ID. The common pitfalls are counting only the sender side, which breaks Example 2 where Amy is a receiver, and forgetting that a self-call must not create a user entry at all. With up to 200000 rows, this runs in linear time and fits comfortably. Return an empty string when the map is empty. Don't sort every user, one pass is enough. StealthCoder is the hedge if you freeze on the symmetric-set idea during the live OA.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Most Active Caller by Distinct Contacts cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Google's OA.
Google reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Most Active Caller by Distinct Contacts FAQ
How hard is the Most Active Caller problem really?+
Easy to medium. There's no clever algorithm, just a hash map of sets and careful edge cases. Most people who fail it miss the symmetric contact rule or the self-call exclusion, not the data structure.
What's the trick to counting distinct contacts?+
Store a set of contacts per user and add both directions for every row. The set removes duplicates automatically, so repeated messages between the same pair count once. Then take the max set size across all users.
How do I handle ties?+
Compare set sizes first. If sizes are equal, keep the lexicographically smaller user ID. You can do this in a single pass over the map without sorting, using a simple string comparison.
What edge cases should I test before submitting?+
Test an empty list, which returns an empty string. Test a self-call, which must not add a contact or create a user. Test repeated pairs in both directions, and a tie between users like Example 2.
How do I prepare for this in 48 hours?+
Write the hash map of sets solution from scratch twice, and run all three examples by hand. Then practice other degree-counting graph problems so the pattern feels automatic. Watch for the input size, 200000 rows, and keep it linear.