Compare temp [ a [ i ] ] with distance from its previous occurence and store the maximum
temp [ a [ i ] ] = Math . Max ( temp [ a [ i ] ] , i - mp [ a [ i ] ] ) ; if ( mp . ContainsKey ( a [ i ] ) ) { mp [ a [ i ] ] = i ; } else { mp . Add ( a [ i ] , i ) ; } } for ( int i = 1 ; i <= n ; i ++ ) {