We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
class Result {
/*
* Complete the 'kSub' function below.
*
* The function is expected to return a LONG_INTEGER.
* The function accepts following parameters:
* 1. INTEGER k
* 2. INTEGER_ARRAY nums
*/
public static long kSub(int k, List<Integer> nums) {
long count =0;
long[] mod = new long[k];
mod[0]=1;
long sum = 0;
for(int i = 0;i<nums.size();i++){
sum+=nums.get(i);
int rem =(int) sum%k;
count+=mod[rem];
mod[rem]++;
}
return count;
}
}
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
K-Subarrays
You are viewing a single comment's thread. Return to all comments →
}