Your question is Optimize Array Pairing Cost. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
You are given an integer array nums. In one operation, you may choose any two elements, remove them, and pay a cost equal to the absolute difference of the two values. Continue until no more pairs can be formed. Return the minimum possible total cost.
Implement min_pair_cost(nums) and assume nums may contain duplicates and negative values. If the array has an odd length, one element will remain unpaired and contributes no cost.
def min_pair_cost(nums):