Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in 3rd party category for Can Balance by kazuki.h
from typing import Iterable
import numpy as np
def can_balance(weights: Iterable) -> int:
n = len(weights)
weights = np.array(weights)
for i in range(n):
left = weights[0:i+1][::-1]
right = weights[i:]
l = len(left)
r = len(right)
if np.dot(left, np.array(range(l))) == np.dot(right, np.array(range(r))):
return i
return -1
Nov. 17, 2021
Comments: