DEV Community

Tshihab07
Tshihab07

Posted on

2 1

Hackerrank - Sherlock and Array Solution in Python

Time Complexity of the program O(n).
if the middle value is q and the sum is p then we can write the equation as follow

  1. p + q + p = sum [as the left and the right sum are same]
  2. 2p = sum - q

According to that Mathematical Logic The code can be written as follow:

def balancedSums(arr):
    # Write your code here
    left_sum = 0
    arr_sum = sum(arr)

    for i in arr:

        if (2 * left_sum) == arr_sum - i:
            return "YES"

        left_sum += i

    return "NO"
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more