MEDIUMasked at 4 companies

Least Number of Unique Integers after K Removals

A medium-tier problem at 63% community acceptance, tagged with Array, Hash Table, Greedy. Reported in interviews at J.P. Morgan and 3 others.

Founder's read

You're given an array and K removals. The goal: minimize the number of distinct integers left. It sounds simple until you realize the greedy choice isn't obvious. J.P. Morgan, Expedia, IBM, and Salesforce have all asked this. The acceptance rate sits at 63%, which means a solid chunk of candidates either miss the pattern or implement it wrong. This is the kind of problem where the right insight takes 30 seconds and the wrong approach eats your entire timer. If you hit this live and blank on the strategy, StealthCoder solves it invisibly while you stay in control.

Companies asking
4
Difficulty
MEDIUM
Acceptance
63%

Companies that ask "Least Number of Unique Integers after K Removals"

If this hits your live OA

Least Number of Unique Integers after K Removals 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. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.

Get StealthCoder
What this means

The trick is frequency-based greedy: count how many times each integer appears, sort those frequencies, then remove the integers with the smallest counts first. That way you eliminate the most distinct values per removal. The obvious mistake is trying to remove individual elements or greedy by value rather than by count. Once you lock in 'sort frequencies, then pop the smallest', the code is five lines. Hash Table counts the frequencies. Sorting orders them. Greedy tells you which ones to axe. Array iteration at the end checks what's left. Common pitfall: confusing 'remove K elements' with 'remove from K distinct integers'. StealthCoder runs invisibly during your assessment and surfaces the frequency-sort-greedy sequence if you stall.

Pattern tags

The honest play

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

Least Number of Unique Integers after K Removals recycles across companies for a reason. It's medium-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. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Least Number of Unique Integers after K Removals interview FAQ

Is this actually a greedy problem or a trick question?+

It's genuinely greedy, but the greedy choice is counterintuitive. You're not removing the largest or smallest values. You're removing the least frequent ones first. That's the pattern companies test for. Once you see it, it's locked in.

Why do J.P. Morgan and Salesforce ask this if the acceptance rate is already 63%?+

High acceptance doesn't mean it's easy. It means candidates who prep know the pattern. You're competing against people who've drilled it. The companies ask it to filter for pattern recognition under pressure, not just code speed.

What's the trap that costs candidates time?+

Trying to decide which specific elements to remove instead of thinking in terms of frequencies and counts. Or iterating through K removals one by one and updating the array each time. Hash Table plus sorting beats simulation every time.

How does this relate to the other topics, Counting and Array?+

Counting is the foundation: you count frequencies with a Hash Table. Array or list is what you iterate through at the end to return the result. Both are scaffolding for the greedy logic.

Will I see this on HackerRank or similar platforms under a different name?+

Possibly, but the problem statement will always boil down to the same idea: minimize distinct elements after X removals. The name or framing may shift. The core pattern doesn't.

Want the actual problem statement? View "Least Number of Unique Integers after K Removals" 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.