Determine Most Frequent Product Color in Carts
Company: Point72
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates proficiency in frequency analysis and deterministic tie-breaking for string data, assessing correctness in counting and selection logic.
Constraints
- 1 <= len(colors) <= 100000
- Each color is a non-empty string of lowercase English letters (a-z)
- 1 <= len(color) <= 30
- Lexicographic order is standard string order (e.g., 'blue' < 'red')
Examples
Input:
Expected Output: red
Input:
Expected Output: blue
Hints
- Use a hash map (dictionary) to count occurrences of each color.
- Track the best (count, color) pair: prefer higher count, and for ties prefer smaller color.
- You can iterate the frequency map once to find the answer in O(k), where k is the number of distinct colors.