Python O(n) solution, easy to understand
At beginning, calculate the total distance that put all the balls into the first box, and also calculate how many balls are after the first box (including it se
At beginning, calculate the total distance that put all the balls into the first box, and also calculate how many balls are after the first box (including it self). \nAnd runs again to put the distance in the answer list, the first distance is already been calculated, then the question is how we calculate the remaining? By moving forward one box, all the balls behind are 1 distance less, and the balls behind are 1 distance added, so the thing is to know how many balls are after and before the box, then we can calculate for each box by add the amount of balls before and minus the amount of balls after the box. \nThe time complexity is O(n) * 2 ~= O(n)\n```\nclass Solution:\n    def minOperations(self, boxes: str) -> List[int]:\n        l = len(boxes)\n        ans = [0] * l\n        before = 0\n        after = 0\n        num = 0\n        for i in range(l):\n            if boxes[i] == "1":\n                after += 1\n                num += i\n        for i in range(l):\n            ans[i] = num\n            if boxes[i] == "1":\n                before += 1\n                after -= 1\n            num += before - after\n        return ans\n```\nThis is my first post, feel free to comment or discuss, thank you!
['Python', 'Python3']