Skip to content

Instantly share code, notes, and snippets.

@mk6619
Created December 4, 2019 12:41
Show Gist options
  • Select an option

  • Save mk6619/91f081b1be26ae989ec9e05def9fc1ff to your computer and use it in GitHub Desktop.

Select an option

Save mk6619/91f081b1be26ae989ec9e05def9fc1ff to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main() {
//code
int testCases;
cin>>testCases;
for(int i = 0 ; i < testCases; i++) {
int n;
cin>>n;
int arr[n];
int sum = 0;
for(int j =0 ; j < n ; j++) {
cin>>arr[j];
sum+=arr[j];
}
int tempSum=0;
bool equiPointFound = false;
int indexOfEquiPoint;
if(n<2) {
equiPointFound = true;
indexOfEquiPoint = 1;
} else if (n==2) {
equiPointFound = false;
} else {
for(int j =1 ; j < n-1 ; j++) {
tempSum+=arr[j-1];
if(tempSum == sum-(tempSum + arr[j])) {
equiPointFound = true;
indexOfEquiPoint = j+1;
}
}
}
if(equiPointFound) {
cout<<indexOfEquiPoint<<endl;
} else {
cout<<-1<<endl;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment