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