Ad
  • Default User Avatar

    I think the clever thing of this solution is that you will only iterate arr to do the sum once. In the current top solution you iterate over it and do the sum len(arr) times making it O(n^2). Also, by using enumerate instead of range(len(arr)) you are already getting the element of the list to add it or substract it from the variables currently containing the sums.