LeetCode solutions

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 17ms, memory 17.7MB, accepted 2025-12-31.

python
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

Source