Find Second largest element in an array | Function to print second largest elements ; There should be atleast two elements ; Find the largest element ; Find the second largest element ; Driver code
def print2largest ( arr , arr_size ) : NEW_LINE INDENT if ( arr_size < 2 ) : NEW_LINE INDENT print ( " ▁ Invalid ▁ Input ▁ " ) ; NEW_LINE return ; NEW_LINE DEDENT largest = second = - 2454635434 ; NEW_LINE for i in range ( 0 , arr_size ) : NEW_LINE INDENT largest = max ( largest , arr [ i ] ) ; NEW_LINE DEDENT for i in range ( 0 , arr_size ) : NEW_LINE INDENT if ( arr [ i ] != largest ) : NEW_LINE INDENT second = max ( second , arr [ i ] ) ; NEW_LINE DEDENT DEDENT if ( second == - 2454635434 ) : NEW_LINE INDENT print ( " There ▁ is ▁ no ▁ second ▁ " + " largest ▁ element " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " The ▁ second ▁ largest ▁ " +   " element is " , second ) ; NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 12 , 35 , 1 , 10 , 34 , 1 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print2largest ( arr , n ) ; NEW_LINE DEDENT