Basic example
Input
arr = [1, 2, 3, 4], k = 2
Output
2
Remainders are [1,0,1,0]. There are two pairs with the same remainder: indices (0,2) and (1,3).
Full lesson preview
Count unordered pairs of array elements whose remainders modulo k are equal using hashing.
Problem statement
Task
Examples
Input
arr = [1, 2, 3, 4], k = 2
Output
2
Remainders are [1,0,1,0]. There are two pairs with the same remainder: indices (0,2) and (1,3).
Input format
Output format
Constraints
Samples
Input
arr = [5, 17, 9, 13, 1], k = 6
Output
2
Remainders: [5,5,3,1,1]. Pairs: two remainders 5 -> 1 pair, two remainders 1 -> 1 pair, total 2.