In case of duplicates we reach last occurrence here
if arr [ i ] == n - i - 1 : NEW_LINE INDENT return arr [ i ] NEW_LINE DEDENT if arr [ n - 1 ] == 0 : NEW_LINE return arr [ n - 1 ] NEW_LINE return - 1 NEW_LINE