It is same as explained in above loop .
if ( hm . size == k && ( r - l ) >= ( j - i ) ) { l = i ; r = j ; } } if ( hm . has ( arr [ i ] ) && hm . get ( arr [ i ] ) == 1 ) hm . delete ( arr [ i ] ) ; else if ( hm . has ( arr [ i ] ) ) hm . set ( arr [ i ] , hm . get ( arr [ i ] ) - 1 ) ; } if ( l == 0 && r == n ) document . write ( " " ) ; else document . write ( l + " " + r ) ; }