Created
March 4, 2022 13:43
-
-
Save theabbie/8e992e54d791db6b2b579300c177d296 to your computer and use it in GitHub Desktop.
Dcoder Panda's Average Solution
This file contains hidden or 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
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