FastPrepMinimum Cost to Make Array Equal
Problems/Minimum Cost to Make Array Equal

Minimum Cost to Make Array Equal

Walmart logoWalmart● HardFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names the well-known Minimum Cost to Make Array Equal problem but leaves out the function signature, examples, and limits. Our version is about 95% the same as the reported question.

You are given two arrays nums and cost of equal length. In one operation, you may increase or decrease nums[i] by 1 and pay cost[i].

You may perform any number of operations. Return the minimum total cost needed to make every value in nums equal.

Function

minCost(nums: int[], cost: int[]) → long

Examples

Example 1

nums = [1,3,5,2]cost = [2,3,1,14]return = 8

Making every value 2 costs 2 + 3 + 3 + 0 = 8.

Example 2

nums = [2,2,2,2,2]cost = [4,2,8,1,3]return = 0

The values are already equal.

Constraints

  • 1 <= nums.length == cost.length <= 10^5.
  • 1 <= nums[i], cost[i] <= 10^6.
  • The answer fits in a signed 64-bit integer.

More Walmart Online Assessment questions

  • Largest Team Where Every Pair OverlapsOA · Seen Nov 2026
  • House RobberOA · Seen Sep 2026
  • Maximum Points by Deleting ElementsOA · Seen Sep 2026
  • Distinct Bitwise-OR Scores of Increasing SubsequencesOA · Seen Sep 2026
  • Best Meeting PointOA · Seen Sep 2026
  • Minimum Stress PathOA · Seen Aug 2026
  • K-Capable Model CostsOA · Seen Jun 2026
  • K-Capable Model SelectionOA · Seen Jun 2026
  • Minimum Moves to Equal Candy BarsOA · Seen Oct 2024
  • Find Length of Longest Good SubsequenceOA · Seen Feb 2024

Similar questions at other companies

  • Count Lamps Lighting Each PointAirbnb · OAAirbnb interview questions
  • Choose ContainersIMC Trading · OAIMC Trading interview questions
  • Calculating QuantilesIndeed · OAIndeed interview questions
  • Count Lamps Lighting Each PointCapital One · OACapital One interview questions
  • Sliding Window MedianAuxoAI · OA
  • Maximum Non-Decreasing Array LengthVisa · OAVisa interview questions
  • Longest Subarray with Sum at Most KGoogle · OAGoogle interview questions
  • Temporal AnomaliesInMobi · OAInMobi interview questions
  • Use Minimum TokensAmazon · OA
  • Subscription and Usage-Based Billing CalculatorStripe · OAStripe interview questions
All Walmart interview questionsSee Walmart hiring insights
Saved
class Solution {
    public long minCost(int[] nums, int[] cost) {
        // write your code here
    }
}
Checking account…