find the equilibrium index of an array reference https www geeksforgeeks orgequilibriumindexofanarray python doctest can be run with the following command python m doctest v equilibriumindex py given a sequence arr of size n this function returns an equilibrium index if any or 1 if no equilibrium index exists the equilibrium index of an array is an index such that the sum of elements at lower indexes is equal to the sum of elements at higher indexes example input arr 7 1 5 2 4 3 0 output 3 find the equilibrium index of an array args arr listint the input array of integers returns int the equilibrium index or 1 if no equilibrium index exists examples equilibriumindex7 1 5 2 4 3 0 3 equilibriumindex1 2 3 4 5 1 equilibriumindex1 1 1 1 1 2 equilibriumindex2 4 6 8 10 3 1 find the equilibrium index of an array args arr list int the input array of integers returns int the equilibrium index or 1 if no equilibrium index exists examples equilibrium_index 7 1 5 2 4 3 0 3 equilibrium_index 1 2 3 4 5 1 equilibrium_index 1 1 1 1 1 2 equilibrium_index 2 4 6 8 10 3 1
def equilibrium_index(arr: list[int]) -> int:
    
    total_sum = sum(arr)
    left_sum = 0

    for i, value in enumerate(arr):
        total_sum -= value
        if left_sum == total_sum:
            return i
        left_sum += value

    return -1


if __name__ == "__main__":
    import doctest

    doctest.testmod()