You are viewing a single comment's thread. Return to all comments →
No need to sum(arr) at all, that would cause another uneccesary O(n), here's my code:
def solve(a, size):
# Complete this function
difference = 0
left_index = 0
compare_count = size - 1
for i in xrange(size+1):
if difference > 0:
difference -= a[compare_count + left_index - i]
difference += a[left_index]
left_index += 1
return 'YES' if difference == 0 else 'NO'
Failed Testcase 1!
Thanks for feedback, code was updated and it passed all cases.