Description
Given an integer array nums, return the most frequent even element. If there is a tie, return the smallest one. If there is no even element, return -1.
Examples
Input:
nums = [0,1,2,2,4,4,1]Output:
2Explanation:
2 and 4 appear twice, 2 < 4.
Input:
nums = [6,8,6,10,10,8,12]Output:
6Explanation:
All even numbers appear twice: 6, 8, 10, and 12 each appear 2 times. Since they have the same frequency, the smallest one (6) is returned.
Input:
nums = [3,7,9,11]Output:
-1Explanation:
All numbers in the array are odd (3, 7, 9, 11), so there are no even elements. The result is -1.
Constraints
- •
1 ≤ nums.length ≤ 2000