Most Frequent Even Element

Given an integer array nums, return the most frequent even element.

If there is a tie, return the smallest one. If there is no such element, return -1.

Example 1
Inputnums = [0,1,2,2,4,4,1]
Output2
The even elements are 0, 2, and 4; 2 and 4 appear the most, so the smallest one, 2, is returned.
Example 2
Inputnums = [4,4,4,9,2,4]
Output4
4 is the even element that appears the most.

Constraints

  • 1 <= nums.length <= 2000
  • 0 <= nums[i] <= 10^5

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate