Created
December 18, 2022 16:59
-
-
Save imsaravana369/e1201d313f5d9365e2e8562e4fcfba62 to your computer and use it in GitHub Desktop.
Area Under the hill
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solve(self, A): | |
A.append(0) | |
n = len(A) | |
res = 0 | |
x = 1 | |
for i in range(1,n): | |
res += x*A[i] | |
x+=1 | |
x = 1 | |
for i in A: | |
res -= i * x | |
x +=1 | |
res = abs(res) | |
return res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment