Equilibrium Point

PHOTO EMBED

Fri Nov 04 2022 13:00:04 GMT+0000 (Coordinated Universal Time)

Saved by @Ranjan_kumar #c++

public:
    // Function to find equilibrium point in the array.
    // a: input array
    // n: size of array
    int equilibriumPoint(long long a[], int n) {
    long long p=0;
    for(int i=0;i<n;i++)
    {
        p+=a[i];
    }
    long long a1[n];
    long long a2[n];
    a1[0]=-1;
    a2[n-1]=-1;
    int p1=0;
    int p2=0;
    for(int i=1;i<n;i++)
    {
        p1+=a[i-1];
        a1[i]=p1;
    }
    for(int i=n-2;i>=0;i--)
    {
        p2+=a[i+1];
        a2[i]=p2;
    }
    for(int i=0;i<n;i++)
    {
        if(a1[i]==a2[i])
        {
            return i+1;
        }
    }
    return -1;
content_copyCOPY

https://practice.geeksforgeeks.org/problems/equilibrium-point-1587115620/1?utm_source=gfg&utm_medium=article&utm_campaign=bottom_sticky_on_article