Subtract the A [ i - M ] and add the A [ i ] in the map
if ( m . ContainsKey ( i - M ) ) { val = i - M ; m . Remove ( i - M ) ; m . Add ( i - M , val - 1 ) ; } if ( m . ContainsKey ( A [ i ] ) ) { val = m [ A [ i ] ] ; m . Remove ( A [ i ] ) ; m . Add ( A [ i ] , val + 1 ) ; } else { m . Add ( A [ i ] , 1 ) ; } val = Math . Max ( val , m [ A [ i ] ] ) ; val = 0 ;