Count with current character
var curr = 0 ; for ( var i = 0 ; i <= n - k ; i ++ ) { if ( s [ i ] !== ch ) continue ; var cnt = 0 ; while ( i < n && s [ i ] === ch && cnt !== k ) { i ++ ; cnt ++ ; } i -- ;