Created
December 4, 2019 12:41
-
-
Save mk6619/91f081b1be26ae989ec9e05def9fc1ff to your computer and use it in GitHub Desktop.
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
| #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