Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
very clear solution in Clear category for Can Balance by rafal.pawlowski
from typing import Iterable
def can_balance(weights: Iterable) -> int:
for i in range(len(weights)):
left = weights[:i][::-1]
right = weights[i+1:]
if sum((nl + 1) * l for nl, l in enumerate(left)) == sum((nr + 1) * r for nr, r in enumerate(right)):
return i
else:
return -1
April 10, 2019
Comments: