You are viewing a single comment's thread. Return to all comments →
public static int divisibleSumPairs(int n, int k, List<Integer> ar) { Map<Integer, Integer> remainderCounts=new HashMap<>(); long count=0; for (int i=0; i<n; i++) { int rem1=ar.get(i) % k; if (rem1!=0) count+=remainderCounts.getOrDefault(k-rem1, 0); else count+=remainderCounts.getOrDefault(0, 0); remainderCounts.put(rem1, remainderCounts.getOrDefault(rem1, 0)+1); } return (int) count; }
Seems like cookies are disabled on this browser, please enable them to open this website
Divisible Sum Pairs
You are viewing a single comment's thread. Return to all comments →