Leetcode 1769. Minimum Number of Operations to Move All Balls to Each Box
Given a binary string where '1' marks a ball in a box, compute for each index the minimum total number of adjacent moves required to move all balls to that box — equivalently the sum of distances from that index to every '1'. The challenge is to avoid O(n^2) distance summation and use cumulative counts/distances (prefix/suffix) to get an O(n) solution.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
0
Hello Interview Premium
Your account is free and you can post anonymously if you choose.