PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick 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.

  • Medium
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Find most frequent log user

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Onsite

##### Question You are given a list of log entries in string format, where each entry contains a username and an access timestamp separated by a delimiter (e.g., "alice 2025-07-27T12:30:00Z"). Design an algorithm that processes the logs and returns the username that appears most frequently (i.e., the user with the highest number of accesses). If multiple users tie for the highest frequency, you may return any one of them. Discuss the time- and space-complexity of your solution.

Quick Answer: 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.

You are given a list of log entry strings. Each entry is formatted as 'username timestamp' where username is the substring before the first whitespace and timestamp follows after at least one space (e.g., 'alice 2025-07-27T12:30:00Z'). Return the username that appears most frequently across all entries. If multiple users tie for the highest frequency, return any one of them. Usernames are case-sensitive. The input list is non-empty and every entry contains at least two whitespace-separated tokens.

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

  1. Split each log entry by whitespace and use the first token as the username.
  2. Use a hash map (dictionary) to count the frequency of each username.
  3. After counting, select the username with the maximum count.
Last updated: Mar 29, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Implement Top-p (Nucleus) Sampling in NumPy - Amazon (medium)
  • Implement Multi-Head Attention from Scratch in NumPy - Amazon (medium)
  • Detect and Break a Cycle in a Singly Linked List - Amazon (medium)
  • Caesar Cipher with Translation-Table Optimization - Amazon (medium)
  • Minimum Drone Delivery Time on a Ring of Hubs - Amazon (medium)