Created
July 7, 2022 12:35
-
-
Save AhmedAbouelkher/858a8bc4fe6ce6c282e43bb418a4ce22 to your computer and use it in GitHub Desktop.
Toptal Quiz 3 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
def solution(S: float, B: list[float]) -> list[float]: | |
total = 0 | |
for i, v in enumerate(B): | |
total += v | |
B = sorted(B, reverse=True) | |
R = list(len(B) * [0]) | |
for i, num in enumerate(B): | |
if i > 0: | |
S = abs(S - R[i - 1]) | |
result = S * num / total | |
R[i] = round(result, 2) | |
total -= num | |
return R | |
if __name__ == '__main__': | |
print(solution(300.01, [300, 200, 100])) | |
print(solution(1.00, [0.05, 1.00])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment