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.
importjava.io.*;importjava.util.*;importjava.util.Scanner;publicclassConsecutiveSubsequences{publicstaticvoidmain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */Scannerscanner=newScanner(System.in);intt=scanner.nextInt();while(t-->0){int[]cnt=newint[100];intn=scanner.nextInt();intk=scanner.nextInt();cnt[0]=1;intsum=0;for(inti=0;i<n;i++){intnum=scanner.nextInt();sum=(sum+num)%k;cnt[sum]++;}longret=0;for(inti=0;i<k;i++){ret+=(long)cnt[i]*(cnt[i]-1)/2;}System.out.println(ret);}scanner.close();}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Consecutive Subsequences
You are viewing a single comment's thread. Return to all comments →
Java 8 solution: