Company: Deutsche_Bank_IIT_Guwahati (Graduate Analyst role)
Difficulty: medium
Maximum Number with Same Occurrences Problem Description Given an integer array, you need to return the maximum number that has the same number of occurrences in the given array as its value. If there are multiple numbers that satisfy this condition, return the largest one. If there is no such number, return -1. This is considered an easy map-based problem. 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