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