Given an array, I would like to find an index, that the numbers before it, and the numbers after it gives equal sum.
for example an array like
[4,5,6,11,7,8]
output is index 3 because 4+5+6 = 7+8
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First find sum of all items, save it as
sum, then read from start of array and sum up items to arrive to(sum - current index value)/2, if you didn’t get such result, means there isn’t such an index, also if you getsum/2in each index of iteration, means related index is your answer.Sample:
4,5,6,11,7,8sum = 41.