Back to problems Sign in to unlock
Leetcode
Medium
Arrays
Hash Maps
Number Theory
Check If Any Element Has Prime Frequency
Determine whether any value in an array appears a prime number of times.
Acceptance 100%
Problem Statement
Problem
Given an integer array, check whether at least one distinct element occurs a prime number of times.
Return true if such an element exists; otherwise return false.
A prime number is an integer greater than 1 that has exactly two divisors: 1 and itself.
Notes
- Frequency is counted over identical values in the array.
- The array may contain duplicates and negative values.
- You only need to know whether any frequency is prime, not which element has it.
Input Format
- A single integer array
nums.
Output Format
- Return
trueif some element frequency is prime, otherwisefalse.
Constraints
1 <= nums.length- Values may be any integers representable by the platform.
- Frequencies are based on exact equality of values.
Examples
Sample cases returned by the problem API.
Example 1
Input
nums = [1,2,3,4]
Output
false
Explanation
Each element appears once, and 1 is not a prime number.
Example 2
Input
nums = [1,1,2,2,2,3]
Output
true
Explanation
The value 2 appears 3 times, and 3 is prime.
Show 1 more example
Example 3
Input
nums = [7,7,7,7]
Output
false
Explanation
The only frequency is 4, which is not prime.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.
Guided hints
Editorial and discussion links
Concept map and variants
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.