← ALL NOTES
Array

2333. Minimum Sum of Squared Difference

k1 and k2 look like two budgets and they are one. Adding 1 to nums1[i] and subtracting 1 from nums2[i] do the same thing to |nums1[i] - nums2[i]|, so the only quantity that matters is k = k1 + k2: that many unit decrements, spendable on any gap. Widening a gap is never useful, and pushing one past zero into negative territory only makes the square grow again, so each unit either shrinks a positive gap by 1 or is wasted.

Loading…