Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Can Balance by logicalladybuglifestyle
from typing import Iterable
def can_balance(weights: Iterable) -> int:
if len(weights) < 3:
return 0
for i in range(1, len(weights)):
L = sum([weights[j] * (i - j) for j in range(i)])
R = sum([weights[j] * (len(weights) - i + j) for j in range(-1, i - len(weights), -1)])
if L == R:
return i
return -1
April 28, 2020