Sherlock and Array

  • + 2 comments

    Python solution. Comments would be appreciated

    # Enter your code here. Read input from STDIN. Print output to STDOUT
    def exists_element(size, arr):
        sum_left = 0
        sum_right = sum(arr)
        previous = 0
        for idx in range(0, size):
            current = arr[idx]
            sum_left += previous
            sum_right -= current
            if sum_left == sum_right:
                return "YES"
            previous = current
        return "NO"
    
    test_cases = int(raw_input())
    for i in range(0, test_cases):
        size = int(raw_input())
        arr = map(int, raw_input().split())
        print exists_element(size, arr)