🎯 Find Median Given Frequency of Numbers
You're given a compressed database where numbers and their frequencies are stored in a special format. Your task is to find the median of all the numbers as if they were fully expanded in the database.
What is a median? The median is the middle value that separates the higher half from the lower half of a data sample. For an odd number of elements, it's the middle element. For an even number of elements, it's the average of the two middle elements.
The Challenge: Instead of storing each number individually (which would waste space), the database stores each unique number with its frequency. You need to "decompress" this data mentally and find the median without actually expanding the entire dataset.
Input: A table Numbers with columns:
num(int): A unique number in the databasefrequency(int): How many times this number appears
Output: The median value rounded to one decimal place.
Example: If you have numbers [1,1,2,2,2,3], the sorted array is [1,1,2,2,2,3] with 6 elements. The median is (2+2)/2 = 2.0
Input & Output
Constraints
- 1 ≤ Numbers.length ≤ 500
- -104 ≤ num ≤ 104
- 1 ≤ frequency ≤ 106
- The sum of all frequencies is between 1 and 109
- Guaranteed: All num values are unique