Find most frequent log user
Company: Amazon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Overview: This question evaluates frequency-counting and log-parsing skills along with algorithmic reasoning about time and space complexity for identifying the most frequent element in a dataset.
Constraints
- 1 <= len(logs) <= 200000
- Each entry contains at least two tokens separated by whitespace
- Username has no whitespace
- Timestamps may be any strings without whitespace; their format is irrelevant
- Usernames are case-sensitive
- Return any one username if multiple have the same maximum frequency
Examples
Input:
Expected Output: alice
Input:
Expected Output: charlie
Hints
- Split each log entry by whitespace and use the first token as the username.
- Use a hash map (dictionary) to count the frequency of each username.
- After counting, select the username with the maximum count.