Compare temp [ i ] with distance of its last occurence from the end of the array and store the maximum
if ( temp [ i ] != - 1 ) { if ( mp . ContainsKey ( i ) ) { temp [ i ] = Math . Max ( temp [ i ] , n - mp [ i ] ) ; } else { temp [ i ] = Math . Max ( temp [ i ] , n ) ; } } } }