3914. Check if Any Element Has Prime Frequency
My accepted Python solution to LeetCode problem 3914, Check if Any Element Has Prime Frequency, running in 6ms.
- Difficulty: Easy
- Python
- Runtime 6ms
- Memory 17.5MB
- 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 6ms, memory 17.5MB, accepted 2025-12-31.
class Solution:
def checkPrimeFrequency(self, nums: List[int]) -> bool:
def is_prime(n):
if n < 2:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
from collections import Counter
freq = Counter(nums)
return any(is_prime(f) for f in freq.values())