Make Numbers Equal
Reported by candidates from Xperi's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
You've got an Xperi OA coming up in the next 48 hours and "Make Numbers Equal" is on the table. This problem hits a pattern candidates either nail or totally miss. The core idea is finding the minimum operations to transform a list so every element matches. It's not about brute force. It's about recognizing what target value minimizes total cost, then calculating the cheapest path to get there. StealthCoder will be your safety net if you blank on the trick during the live assessment.
Pattern and pitfall
The trick here is that the optimal target is almost always the median (or mean, depending on the operation allowed). Once you pick your target, you count or sum the differences between each element and that target. The common pitfall is trying every possible target value, which is slow. Instead, think about what value minimizes the sum of absolute differences (median) or sum of squared differences (mean). If the problem allows specific operations like incrementing or decrementing, you may need to count total moves. Build your solution in steps: identify the operation type, compute the optimal target, then aggregate costs. If you freeze during the OA, StealthCoder reads the exact wording and serves the pattern in seconds.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Make Numbers Equal cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Xperi's OA.
Xperi reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Make Numbers Equal FAQ
Is this a greedy problem or do I need DP?+
Greedy. Pick the mathematically optimal target (median or mean depending on cost function), then sum costs. No need to explore multiple states. DP is overkill here and signals you're overthinking it.
What if the array is really large?+
Compute the median in O(n log n) time using sorting, then iterate once to sum differences. Total is O(n log n). If n is 10^5 or 10^6, this still passes comfortably.
How do I know if it's median or mean?+
Read the operation carefully. If you're counting the number of increments/decrements to reach a target, median minimizes absolute differences. If cost is squared differences, use mean. The problem text will clarify what counts as a 'cost' or 'operation'.
Should I check edge cases like single-element arrays?+
Yes. A single element array costs zero because it's already equal to itself. Empty arrays should be handled too, though unlikely in the actual OA. Test your median/mean logic on very small inputs first.
Will Xperi ask me to optimize further or print the operations?+
Most likely they want the minimum cost as a number. Some variants ask you to print the actual sequence of operations, which is straightforward once you know the target. Clarify the output format in the problem statement immediately.