One of the two distinct must appear exactly once . Either the first entry appears once , or it appears n / k - 1 times to make other substring appear once .
for ( let [ key , value ] of mp . entries ( ) ) { if ( value == ( Math . floor ( n / k ) - 1 ) value == 1 ) return true ; } return false ; }