Sherlock and Array

  • + 1 comment

    There is no need to have a separate check for singleton lists.

    def balanced_sums(arr):
        total = sum(arr)
        so_far = 0
        for i in arr:
            if total - i == 2*so_far:
                return 'YES'
            else:
                so_far += i
    
        return 'NO'