It is same as explained in above loop .
if ( hm . Count == k && ( r - l ) >= ( j - i ) ) { l = i ; r = j ; } } if ( hm . ContainsKey ( arr [ i ] ) && hm [ arr [ i ] ] == 1 ) hm . Remove ( arr [ i ] ) ; else if ( hm . ContainsKey ( arr [ i ] ) ) hm [ arr [ i ] ] = hm [ arr [ i ] ] - 1 ; } if ( l == 0 && r == n ) Console . WriteLine ( " Invalid ▁ k " ) ; else Console . WriteLine ( l + " ▁ " + r ) ; }