Find the Most Frequent Log Call
Company: Roblox
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Technical Screen
Quick Answer: This question evaluates a candidate's ability to perform frequency analysis on sequences, demonstrating competency with data structures for counting occurrences and with algorithmic time and space complexity considerations.
Constraints
- 0 <= len(logs) <= 10^6
- Each log entry is a non-empty string of an API/function call name.
- Ties are broken by earliest first appearance in the log sequence.
- Return ("", 0) for an empty log.
Examples
Input: (["login", "search", "login", "checkout", "search", "login"],)
Expected Output: ("login", 3)
Explanation: "login" appears 3 times, more than "search" (2) and "checkout" (1).
Input: (["a", "b", "a", "b"],)
Expected Output: ("a", 2)
Explanation: "a" and "b" both appear twice; "a" appears first, so it wins the tie.
Input: (["solo"],)
Expected Output: ("solo", 1)
Explanation: A single entry is trivially the most frequent.
Input: ([],)
Expected Output: ("", 0)
Explanation: Empty log returns the sentinel ("", 0).
Input: (["x", "y", "z"],)
Expected Output: ("x", 1)
Explanation: All unique with frequency 1; the earliest-appearing "x" wins the tie.
Input: (["api", "api", "api", "api"],)
Expected Output: ("api", 4)
Explanation: A single repeated call accumulates the full count.
Hints
- Use a hash map to count occurrences of each call in a single pass.
- Track each call's first-appearance index so you can break frequency ties deterministically.
- For the top-k follow-up, a heap of size k or bucket sort by frequency avoids fully sorting all distinct calls; for streaming/large-scale, think Count-Min Sketch or a map-reduce word-count.