HARDasked at 1 company

Find Median Given Frequency of Numbers

A hard-tier problem at 42% community acceptance, tagged with Database. Reported in interviews at Pinterest and 0 others.

Founder's read

You hit a hard problem on the OA and it's asking you to find a median with frequency data. Pinterest has asked this. At 42% acceptance, most candidates either overthink it or miss the sorting trick entirely. The setup looks deceptively like a simple stats problem, but the actual work is in how you reconstruct the sorted dataset from frequencies without materializing millions of duplicate values. If you blank on the pattern during the live assessment, StealthCoder solves it invisibly while you keep your composure.

Companies asking
1
Difficulty
HARD
Acceptance
42%

Companies that ask "Find Median Given Frequency of Numbers"

If this hits your live OA

Find Median Given Frequency of Numbers is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround.

Get StealthCoder
What this means

The trap is trying to build an array with actual duplicates. If a number appears 1 million times, you can't allocate that memory. The real approach: sort the frequency map by value, then walk through frequencies cumulatively to find where the median position lands. For even-length datasets, you need both middle elements. For odd-length, the single middle value. The trick is calculating total count first, then using that count to determine which positions you need. Most candidates struggle with the cumulative count logic or mess up the even/odd case handling. This is exactly the kind of live-interview wall where StealthCoder surfaces a clean solution in seconds, letting you paste and move on.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Find Median Given Frequency of Numbers recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Find Median Given Frequency of Numbers interview FAQ

Is this really a database problem or just a data structure problem?+

The topic is labeled Database, which suggests the original or primary context involves SQL queries to compute frequency and find the median directly. The algorithmic version flips it: you're given frequencies and reconstruct the median. Both versions test the same core logic: cumulative frequency and position math.

Why can't I just expand all duplicates into an array?+

Memory. If a value appears 10^6 times, allocating that array fails or times out. You must work with the frequency map directly, using cumulative sums to locate the median position without materializing the full dataset.

How do I handle even vs. odd length datasets?+

Calculate total count first. If odd, the median is the single value at position (count + 1) / 2. If even, you need both values at positions count / 2 and (count / 2) + 1, then average them. Cumulative frequency tells you which value occupies each position.

What's the time complexity and does it matter?+

Sorting the frequency map takes O(n log n) where n is the number of unique values. Walking through to find the median is O(n). This scales well because you're not iterating over raw frequencies, just unique values. Much faster than expanding duplicates.

Is Pinterest the only company asking this?+

According to the data, Pinterest is the reported company. At 42% acceptance and hard difficulty, it's not high-volume across all FAANG, but when it appears, it trips up candidates who don't know the cumulative frequency pattern.

Want the actual problem statement? View "Find Median Given Frequency of Numbers" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.