Most Frequent Element
EasyP3Coding
Return [value, count] for the element that occurs most often in nums. If several values tie for the highest count, choose the smallest value.
Example 1
- Input
- nums = [1,2,2,3,3,3]
- Output
- [3,3]
- Why
- 3 occurs three times.
Example 2
- Input
- nums = [5]
- Output
- [5,1]
- Why
- 1 and 2 tie with two each, so the smaller value 1 wins.
Example 3
- Input
- nums = [1,1,2,2]
- Output
- [1,2]
Constraints
- 1 <= nums.length <= 10^5
- -10^9 <= nums[i] <= 10^9
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 10. ⌘Enter runs, ⌘⇧Enter submits.