Compute array modes with ties and no-mode rule
Company: Amazon
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Technical Screen
Quick Answer: This question evaluates algorithm design and data-structure skills—frequency counting, hashing, and handling edge cases such as ties and a no-mode rule—within the coding and algorithms domain for data scientist roles.
Constraints
- nums may be empty.
- Return [] when the highest frequency is 1.
- Multiple modes must preserve first occurrence in the input.
Examples
Input: ([3,1,2,2,3],)
Expected Output: [3, 2]
Explanation: 3 and 2 both occur twice and are ordered by first occurrence.
Input: ([1,2,3],)
Expected Output: []
Explanation: All values are unique, so there is no mode.
Input: ([7,7,7],)
Expected Output: [7]
Explanation: A single repeated value is the only mode.
Input: ([-1,2,-1,2,3],)
Expected Output: [-1, 2]
Explanation: Tied modes preserve first-seen order.
Hints
- Count frequencies and remember first-seen order.
- The no-mode rule applies only when every frequency is 1.