verified code for finding the count of pairs with a diff in an array