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