Problem · Array

Frequency Equals Card Value

Learn this problem
EasyInMobi logoInMobiFULLTIMEPHONE SCREEN

Problem 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[]) → boolean

Examples

Example 1

deck = [1,1,1,2,2,3]return = true

The value 2 appears exactly 2 times, so the condition is satisfied.

Example 2

deck = [1,1,2,2,2,3,3]return = false

The frequencies of values 1, 2, and 3 are 2, 3, and 2. None equals its card value.

Constraints

  • 2 <= deck.length <= 10^4
  • 1 <= deck[i] <= 4 * 10^4

More InMobi problems

drafts saved locally
public boolean hasValueWithMatchingFrequency(int[] deck) {
    // Write your code here
}
deck[1,1,1,2,2,3]
expectedtrue
checking account