You are viewing a single comment's thread. Return to all comments →
Nice work!
My first try was to sum both sides of the pivot and I timed out
Then realised sum the whole array and + / - the pivot
I iterated over the array rather than use indexes
def balancedSums(arr): leftsum = 0 rightsum = sum(arr) for n in arr: rightsum -= n if rightsum == leftsum: return 'YES' leftsum += n return 'NO'
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and Array
You are viewing a single comment's thread. Return to all comments →
Nice work!
My first try was to sum both sides of the pivot and I timed out
Then realised sum the whole array and + / - the pivot
I iterated over the array rather than use indexes