We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

I had a similar idea, but yours is way better. Helped me figure out why mine was so slow:

defsolve(a):# Complete this functioniflen(a)==1:return"YES"foriinrange(1,int(len(a)+1/2)):left=sum(a[:i])right=sum(a[i+1:])ifleft==right:return"YES"breakelse:return"NO"

Instead of computing the sum each time, just subtract. Way more efficient. Thank you for sharing.

## Sherlock and Array

You are viewing a single comment's thread. Return to all comments →

I had a similar idea, but yours is way better. Helped me figure out why mine was so slow:

Instead of computing the sum each time, just subtract. Way more efficient. Thank you for sharing.