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 1) — the data. This set runs 4 cases: nums holds arrays of 5–8 items, with values from 1 to 5. The hidden cases are the largest of the set.
Example 1
mostFrequentValue()
Input
nums =[2,1,4,2,4]
Output
2
Why
`mostFrequentValue` returns `2`forthisinput.
Example 2
mostFrequentValue()
Input
nums =[5,1,2,2,4]
Output
2
Why
`mostFrequentValue` returns `2`forthisinput.
Constraints
1<=nums.length<=10^5-10^4<= nums[i]<=10^4
Every caseinthisset 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.