Add the calculated value of current index to count
if ( cnt . containsKey ( ( pref . get ( i ) - i % k + k ) % k ) ) cnt . put ( ( pref . get ( i ) - i % k + k ) % k , cnt . get ( ( pref . get ( i ) - i % k + k ) % k ) + 1 ) ; else cnt . put ( ( pref . get ( i ) - i % k + k ) % k , 1 ) ; }