Analysis:

First we must calculate the sum of all elements of A,

Tape Equilibrium

Python

6

7

8

N=len(A)

total=sum(A)

left_sum=A[0]

The time complexity for calculating the sum of all elements of an array is O(N), since you have to travel through all elements of the array.
Now that we have the sum of all elements our main strategy will be to visit again each element of A, and for each visited element, we will calculate the value of the left set, and the result of the diff operation. Having the value of the diff operation we’ll compare it with our current result, and if necessary update the current result value.

Since I had to set the variables left_sumand resultbefore entering the loop, I already did a loop iteration, instead of setting their values to random numbers, that’s why we start our for loop from 2. So our for loop has too a O(N) time complexity.
This will give us a total time complexity of O(N) + O(N) which gives us a final time complexity of O(N).For the space complexity, we did O(1), even though we could use a O(N) complexity, I don’t see why should we use it. The reason for the O(1) complexity is pretty simple, we just used five variables to solve this problem, and it will remain five, regardless the size of our input.