2D Array - Count numbers in range [HARD]

Can anyone provide me with a solution other than a brute force?