it is same as explained in above loop .
if ( hm . size ( ) == k && ( r - l ) >= ( j - i ) ) { l = i ; r = j ; } } if ( hm [ arr [ i ] ] == 1 ) hm . erase ( arr [ i ] ) ; else hm [ arr [ i ] ] -- ; } if ( l == 0 && r == n ) cout << " Invalid ▁ k " << endl ; else cout << l << " ▁ " << r << endl ; }