Subtract the A [ i - M ] and add the A [ i ] in the map
if ( m . containsKey ( i - M ) ) { m . put ( i - M , m . get ( i - M ) - 1 ) ; } if ( m . containsKey ( A [ i ] ) ) { m . put ( A [ i ] , m . get ( A [ i ] ) + 1 ) ; } else { m . put ( A [ i ] , 1 ) ; } val = 0 ;