Most Frequent Value (Set 6)

Easy

Given a non-empty array of integers nums, return the value that appears most often. If several values tie, return the smallest of them.

Most Frequent Value (Set 6) — the data. This set runs 4 cases: nums holds arrays of 26–37 items, with values from 1 to 5. The hidden cases are the largest of the set.

Example 1

mostFrequentValue()
Input
nums = [3, 2, 4, 1, 4, 1, 5, 2, 4, 4, 5, 4, 2, 4, 4, 4, 1, 4, 1, 5, 5, 2, 2, 2, 4, 1, 3, 2, 1, 3]
Output
4

Why

`mostFrequentValue` returns `4` for this input.

Example 2

mostFrequentValue()
Input
nums = [5, 1, 1, 5, 3, 1, 4, 4, 5, 2, 2, 1, 2, 1, 3, 4, 4, 1, 2, 2, 3, 2, 4, 4, 3, 4]
Output
4

Why

`mostFrequentValue` returns `4` for this input.
Constraints
1 <= nums.length <= 10^5
-10^4 <= nums[i] <= 10^4
Every case in this set must pass: the first two are visible on Run, the last two unlock on Submit.

Topics

ArraysHash TableCounting

Implement mostFrequentValue in the editor and return the answer — printing it is never graded.