Find the smallest window starting with arr [ i ] and containing exactly k distinct elements .
let s = new Set ( ) ; let j ; for ( j = i ; j < n ; j ++ ) { s . add ( arr [ j ] ) ; if ( s . size == k ) { if ( ( j - i ) < ( r - l ) ) { r = j ; l = i ; } break ; } }