Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Find Lucky Integer in an Array

XPChallenge Points: 10
levelLevel: Easy

You are given an integer array arr.
A number is considered lucky if the count of its occurrences in the array is exactly equal to the number itself.

Your task is to identify the largest integer that satisfies this condition.
If no number in the array meets this requirement, return -1.

Example 1:

Input: arr = [1,2,2]

Output: 2

Explanation:

frequency of 2 is 2 → lucky.

Example 2:

Input: arr = [4,4,4,4]

Output: 4

Explanation:

4 appears 4 times → lucky.

Example 3:

Input: arr = [2,2,3,3,3,4,4,4,4]

Output: 4

Explanation:

4 appears 4 times → lucky 3 appears 3 times → also lucky Return the largest lucky, which is 4.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result