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.
Input: arr = [1,2,2]
Output: 2
Explanation:
frequency of 2 is 2 → lucky.
Input: arr = [4,4,4,4]
Output: 4
Explanation:
4 appears 4 times → lucky.
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.
Accepted:
Submission: