MostFrequentInt

Medium

Given an array of integers, return the most frequent integer.

If multiple numbers are tied for highest frequency, return the largest of them.

Parameter(s):

  • arr: an array of integers

Returns:

  • integer: the most frequent integer

Constraints:

  • arr ≠ null
  • 1 ≤ arr.length ≤ 1000
  • -2147483647 ≤ arr[i] ≤ 2147483647

Example 1:

Input:

[1,2,3,1]

Output:

1

Example 2:

Input:

[1,2,3]

Output:

3

Example 3:

Input:

[4]

Output:

4