Company: Deutsche_Bank_IIT_Guwahati (Graduate Analyst role)
Difficulty: medium
Problem Description Given an integer array, return the maximum number whose number of occurrences in the array equals its own value. If several numbers satisfy this condition, return the largest one among them. If none do, return -1. Examples Example 1 Input: arr = [2,2,3,4] Output: 2 Explanation: The number 2 appears 2 times (frequency equals value). The number 3 appears 1 time. The number 4 appears 1 time. The only valid number is 2. Example 2 Input: arr = [1,2,2,3,3,3] Output: 3 Explanation: 1 appears 1 time. 2 appears 2 times. 3 appears 3 times. All of them meet the condition. We return the maximum, which is 3. Example 3 Input: arr = [2,2,2,3,3] Output: -1 Explanation: There are no numbers in the array where the frequency equals the value. Constraints 1 <= arr.length <= 500 1 <= arr[i] <= 500