HARDasked at 2 companies

Minimum Total Cost to Make Arrays Unequal

A hard-tier problem at 41% community acceptance, tagged with Array, Hash Table, Greedy. Reported in interviews at razorpay and 1 others.

Founder's read

Minimum Total Cost to Make Arrays Unequal is a hard problem asked at Razorpay and Flipkart. With a 40% acceptance rate, it trips up candidates who default to brute-force pairing instead of seeing the greedy structure. The problem forces you to think about optimal assignment under constraints, not just array manipulation. If this lands in your live assessment and you freeze on the greedy choice, StealthCoder surfaces the working solution invisible to the proctor.

Companies asking
2
Difficulty
HARD
Acceptance
41%

Companies that ask "Minimum Total Cost to Make Arrays Unequal"

If this hits your live OA

Minimum Total Cost to Make Arrays Unequal 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 for the engineer who has done the work but might still blank with a webcam pointed at him.

Get StealthCoder
What this means

The core trick is recognizing that you can't just pair elements arbitrarily. You need to count frequencies and match them greedily, prioritizing high-cost swaps first to minimize the total. Most candidates try to iterate through both arrays simultaneously and fail because they don't account for the constraint that each element can only be used once. The hash table step is where you unlock the pattern: group by value, then greedily pair the largest costs. Common pitfall: overthinking element-by-element matching instead of treating it as a frequency assignment problem. When you're stuck mid-OA on the pairing logic, StealthCoder cuts through the noise and gives you the greedy sweep that works.

Pattern tags

The honest play

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

Minimum Total Cost to Make Arrays Unequal 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. Made for the engineer who has done the work but might still blank with a webcam pointed at him. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Minimum Total Cost to Make Arrays Unequal interview FAQ

Why is this problem hard and not medium?+

Because the greedy choice isn't obvious. You need to count frequencies, then pair them in a non-trivial order to minimize cost. Candidates often nail the frequency-counting part but fail the assignment strategy, which is why acceptance hovers at 40%.

Is this still asked at FAANG or just Flipkart and Razorpay?+

Input data shows Razorpay and Flipkart. It's a strong algorithmic signal they care about, so similar greedy-matching patterns appear across many company interviews. Expect variants.

What's the trick I'm missing if the naive approach fails?+

You're probably not using a hash table to count frequencies first. Once you have counts, the greedy insight is: match highest costs to biggest frequency gaps. It's assignment, not iteration.

How do Hash Table and Greedy combine here?+

Hash table groups identical elements and their costs by value. Greedy then picks the order of assignments to minimize total cost. Without the hash table, you can't see which pairs matter most.

How much does Counting actually matter for this problem?+

It's the foundation. You can't solve the assignment problem without knowing how many times each value appears. Counting unlocks the greedy choice.

Want the actual problem statement? View "Minimum Total Cost to Make Arrays Unequal" 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.