Easy Python beats 100% time and space
Similar to 238. Product of Array Except Self and 42. Trapping Rain Water.\nFor each index, the cost to move all boxes to it is sum of the cost leftCost to move 
Similar to **238. Product of Array Except Self** and **42. Trapping Rain Water**.\nFor each index, the cost to move all boxes to it is sum of the cost ```leftCost``` to move all left boxes to it, and the cost ```rightCost``` to move all right boxes to it.\n- ```leftCost``` for all indexes can be calculted using a single pass from left to right.\n- ```rightCost``` for all indexes can be calculted using a single pass from right to left.\n```\nExample:\nboxes      11010\nleftCount  01223\nleftCost   01358\nrightCount 21100\nrightCost  42100\nans        43458\n```\n\n```\nclass Solution:\n    def minOperations(self, boxes: str) -> List[int]:\n        ans = [0]*len(boxes)\n        leftCount, leftCost, rightCount, rightCost, n = 0, 0, 0, 0, len(boxes)\n        for i in range(1, n):\n            if boxes[i-1] == \'1\': leftCount += 1\n            leftCost += leftCount # each step move to right, the cost increases by # of 1s on the left\n            ans[i] = leftCost\n        for i in range(n-2, -1, -1):\n            if boxes[i+1] == \'1\': rightCount += 1\n            rightCost += rightCount\n            ans[i] += rightCost\n        return ans\n```\n\n![image](https://assets.leetcode.com/users/images/3d995443-d359-4b78-8d87-3064999f2fa8_1613890251.8506355.png)
['Python', 'Python3']