Created
March 7, 2020 06:01
-
-
Save SasiZets/ce61227fc5a0dc5cb9188e764b0345b1 to your computer and use it in GitHub Desktop.
Given an array A of N positive numbers. The task is to find the position where equilibrium first occurs in the array. Equilibrium position in an array is a position such that the sum of elements before it is equal to the sum of elements after it. Input: The first line of input contains an integer T, denoting the number of test cases. Then T test…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
List a=[1,4,5,2,2]; | |
int sum=0; | |
int leftSum=0; | |
for(int v in a) | |
sum+=v; | |
for(int i=0;i<a.length;i++){ | |
sum-=a[i]; | |
if(sum==leftSum){ | |
print(a[i]); | |
return; | |
} | |
leftSum+=a[i]; | |
} | |
print('-1'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment