#1769

Minimum Number of Operations to Move All Balls to Each Box

pupil · 360 · lc medium +23 · verified · 90.1% accepted · 3,118 likes · top 99%

Description

You have n boxes described by binary string boxes ('1' = ball, '0' = empty). Moving a ball to an adjacent box costs one operation. Return an array answer where answer[i] is the minimum operations to gather all balls into box i.

Code

1
2
3