Skip to content

Instantly share code, notes, and snippets.

@arafatkamaal
Created November 22, 2019 07:53
Show Gist options
  • Save arafatkamaal/296c18bf10405c7522a8c830a1490a4b to your computer and use it in GitHub Desktop.
Save arafatkamaal/296c18bf10405c7522a8c830a1490a4b to your computer and use it in GitHub Desktop.
Given a array and a number k, find all contigious array sequences that are divisible by k
/*
*
* Given a array and a number k, find all contigious array sequences that are divisible by k
*
*
*
*/
public class KSubsequences {
public static int ksub(int array[], int k) {
int startWindow = 0;
int sum = 0;
int result = 0;
int l = array.length;
while(l != 0) {
for(int i = startWindow; i < array.length; i++) {
sum += array[i];
if (sum % k == 0) {
result++;
}
}
sum = 0;
startWindow++;
l--;
}
return result;
}
public static void main(String args[]) {
System.out.println("Beginning of the program");
System.out.println(ksub(new int[]{5, 10, 11, 9, 5}, 5));
System.out.println(ksub(new int[]{1, 2, 3, 4, 1}, 3));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment