Company: Deutsche Bank IIT Guwahati_12feb
Difficulty: medium
Largest Number with Shared Frequency Problem Description Given an integer array nums , you need to find the largest number X such that its frequency (number of occurrences) in the array is shared by at least one other distinct number Y (where Y != X ) also present in nums . In simpler terms: Count the frequency of each distinct number in the array. Identify all frequencies that are associated with more than one distinct number. Collect all numbers that have these "shared" frequencies. From this collection of numbers, return the maximum value. If no such number exists (i.e., every distinct number in the array has a unique frequency count), 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