nums[i]
with its corresponding cost[i]
and sort the pairs based on the nums
values.totalCost
with the cost of making all elements equal to the smallest value in nums
.nums
, updating totalCost
for each unique value by considering the difference in cost from the previous value.totalCost
encountered during the iteration.totalCost
as the answer.