nums1
and nums2
and store them in an array diff
.M
in diff
.bucket
of size M+1
to count the frequency of each difference.diff
and increment the count in bucket
for each difference.k
as the sum of k1
and k2
.bucket
and increment the count of the next smaller difference, using up the modifications k
.k
is exhausted, calculate the sum of squared differences using the updated bucket
array.