Remove the index at present after K indices from the current index
int remIdx = i - k ; if ( remIdx >= 0 ) { if ( cnt . containsKey ( ( pref . get ( remIdx ) - remIdx % k + k ) % k ) ) cnt . put ( ( pref . get ( remIdx ) - remIdx % k + k ) % k , cnt . get ( ( pref . get ( remIdx ) - remIdx % k + k ) % k ) - 1 ) ; else cnt . put ( ( pref . get ( remIdx ) - remIdx % k + k ) % k , - 1 ) ; }