Problem · Array
Frequency Equals Card Value
Learn this problemProblem statement
You are given an integer array deck, where each integer is the value written on one card.
Return true if there is at least one integer x that appears exactly x times in deck. Otherwise, return false.
Function
hasValueWithMatchingFrequency(deck: int[]) → booleanExamples
Example 1
deck = [1,1,1,2,2,3]return = trueThe value 2 appears exactly 2 times, so the condition is satisfied.
Example 2
deck = [1,1,2,2,2,3,3]return = falseThe frequencies of values 1, 2, and 3 are 2, 3, and 2. None equals its card value.
Constraints
2 <= deck.length <= 10^41 <= deck[i] <= 4 * 10^4