Python | O(N) | DP | Time beats 100% | space beats 100%
\n\n\n\nclass Solution:\n    def minOperations(self, boxes: str) -> List[int]:\n        n = len(boxes)\n        dpleft, dpright = [0]*n, [0]*n\n        countlef
![image](https://assets.leetcode.com/users/images/dc2b12a6-2b9f-4f15-a971-3ef25664d173_1615282750.7098162.png)\n\n\n```\nclass Solution:\n    def minOperations(self, boxes: str) -> List[int]:\n        n = len(boxes)\n        dpleft, dpright = [0]*n, [0]*n\n        countleft, countright = int(boxes[0]), int(boxes[-1])\n        ans = [0]*n\n        \n        for i in range(1, n):\n            dpleft[i] = dpleft[i-1] + countleft\n            if boxes[i] == \'1\':\n                countleft += 1\n        \n        for i in range(n-2, -1, -1):\n            dpright[i] = dpright[i+1] + countright\n            if boxes[i] == \'1\':\n                countright += 1\n        \n        for i in range(len(boxes)):\n            ans[i] = dpleft[i]+dpright[i]\n        \n        return ans\n\t\t\n```\n
['Dynamic Programming', 'Python', 'Python3']