Find the most frequent element in an array. If multiple elements have the same maximum frequency, return the smallest element.
Examples
Example 1
Input: [3, 3, 3, 2, 1]
Output: 3
3 appears most frequently (3 times)
Example 2
Input: [3, 1, 3, 1, 2]
Output: 1
Both 3 and 1 appear twice, return smaller element (1)
Constraints
- Array contains at least 1 element
- Handle ties by returning smallest element