There are easier ways probably, but this would work.
Assume the array.height is 10, and the width is the number of moving pieces.
then just subtract y value difference for the moving pieces. (abs to keep them always positive if needed)
If you don't need the array you could just set variable to the overlapping square value and sum, etc.