Equilibrium index of an array | Python program to find the equilibrium index of an array Function to find the equilibrium index ; Iterate from 0 to len ( arr ) ; If i is not 0 ; Iterate from 0 to len ( arr ) ; If no equilibrium index found , then return - 1 ; Driver code
def equilibrium ( arr ) : NEW_LINE INDENT left_sum = [ ] NEW_LINE right_sum = [ ] NEW_LINE for i in range ( len ( arr ) ) : NEW_LINE INDENT if ( i ) : NEW_LINE INDENT left_sum . append ( left_sum [ i - 1 ] + arr [ i ] ) NEW_LINE right_sum . append ( right_sum [ i - 1 ] + arr [ len ( arr ) - 1 - i ] ) NEW_LINE DEDENT else : NEW_LINE INDENT left_sum . append ( arr [ i ] ) NEW_LINE right_sum . append ( arr [ len ( arr ) - 1 ] ) NEW_LINE DEDENT DEDENT for i in range ( len ( arr ) ) : NEW_LINE INDENT if ( left_sum [ i ] == right_sum [ len ( arr ) - 1 - i ] ) : NEW_LINE INDENT return ( i ) NEW_LINE DEDENT DEDENT return - 1 NEW_LINE DEDENT arr = [ - 7 , 1 , 5 , 2 , - 4 , 3 , 0 ] NEW_LINE print ( ' First ▁ equilibrium ▁ index ▁ is ▁ ' , equilibrium ( arr ) ) NEW_LINE