Company: Deutsche Bank IIT Guwahati_12feb
Difficulty: medium
Largest Number with Shared Frequency Problem Description Given an integer array nums , find the largest number X whose frequency (its count of occurrences) matches the frequency of at least one other distinct number Y (with Y != X ) that also appears in nums . In other words: Work out the frequency of every distinct number in the array. Find every frequency value that belongs to more than one distinct number. Gather every number whose frequency is one of these shared values. Return the largest number in that collection. If no such number exists — meaning every distinct number has a frequency count all its own — return -1 . Examples Example 1: Input: nums = [1, 2, 2, 3, 3, 3, 4, 4, 5] Output: 5 Explanation: - Frequencies: - 1: 1 occurrence - 2: 2 occurrences - 3: 3 occurrences - 4: 2 occurrences - 5: 1 occurrence - Frequencies shared by multiple distinct numbers: - Frequency 1 is shared by numbers {1, 5}. - Frequency 2 is shared by numbers {2, 4}. - Frequency 3 is unique to number 3. -