Divisible Sum Pairs Hacker Rank Problem Solution

Divisible Sum Pairs Hacker Rank Problem Solution

n this Divisible Sum Pairs problem you have Given an array of integers and a positive integer k, determine the number of (i,j) pairs where i < j and ar[i]+ar[j] is divisible by k.

Problem Solution in Java

public static int DivisibleSumPairs(List<Integer> array, Integer k) {
    int result = 0;
    int posicaoI = 0;
    int posicaoJ = 0;


    for (Integer i : array) {
        posicaoJ = 0;
        for (Integer j : array) {
            if ((posicaoI < posicaoJ) && (((i+j)%k) == 0)) {
                result++;
            }
            posicaoJ++;
        }
        posicaoI++;
    }
    return result;
}