2486. Most Frequent Even Element
My accepted Python solution to LeetCode problem 2486, Most Frequent Even Element, running in 17ms.
- Difficulty: Easy
- Python
- Runtime 17ms
- Memory 17.7MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 17ms, memory 17.7MB, accepted 2025-12-31.
class Solution:
def mostFrequentEven(self, nums: List[int]) -> int:
from collections import Counter
even_nums = [n for n in nums if n % 2 == 0]
if not even_nums:
return -1
count = Counter(even_nums)
max_freq = max(count.values())
# Find smallest with max frequency
result = min(n for n, freq in count.items() if freq == max_freq)
return result