Compare temp [ a [ i ] ] with distance from its previous occurence and store the maximum
temp [ a [ i ] ] = max ( temp [ a [ i ] ] , i - mp [ a [ i ] ] ) NEW_LINE mp [ a [ i ] ] = i NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE