Sherlock and Array

  • + 1 comment

    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]
            else:
                difference += a[left_index]
                left_index += 1
        return 'YES' if difference == 0 else 'NO'