Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Simple enumerate solution in Clear category for Can Balance by mindaugas.dadurkevicius
def can_balance(weights):
for i in range(len(weights)):
left_weight = sum([x * (cnt + 1) for cnt, x in enumerate(reversed(weights[:i]))])
right_weight = sum([x * (cnt + 1) for cnt, x in enumerate(weights[i+1:])])
if left_weight == right_weight:
return i
return -1
Aug. 30, 2021
Comments: