Skip to content

Instantly share code, notes, and snippets.

@theabbie
Created March 4, 2022 13:43
Show Gist options
  • Save theabbie/8e992e54d791db6b2b579300c177d296 to your computer and use it in GitHub Desktop.
Save theabbie/8e992e54d791db6b2b579300c177d296 to your computer and use it in GitHub Desktop.
Dcoder Panda's Average Solution
t = int(input())
for _ in range(t):
n = int(input())
arr = input().split()
arr = [int(el) for el in arr]
total = sum(arr)
sums = [0]
mindiff = float('inf')
for el in arr:
sums.append(sums[-1] + el)
m = len(sums)
for i in range(1, n):
mindiff = min(mindiff, abs((sums[i] / i) - ((total - sums[i])/(n - i))))
print("{:.2f}".format(mindiff))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment