Java: O(n) - left sum and right sum
\n\nclass Solution {\n    public int[] minOperations(String boxes) {\n        int n = boxes.length();\n\n        int[] left = new int[n];\n        int[] right =
```\n\nclass Solution {\n    public int[] minOperations(String boxes) {\n        int n = boxes.length();\n\n        int[] left = new int[n];\n        int[] right = new int[n];\n        int[] ans = new int[n];\n\n        int count = boxes.charAt(0) - \'0\';\n        for(int i = 1 ; i < n ; i++){\n            left[i] = left[i - 1] + count;\n            count += boxes.charAt(i) - \'0\';\n        }\n\n        count = boxes.charAt(n - 1) - \'0\';\n        for(int i = n - 2 ; i >=0 ; i--){\n            right[i] = right[i + 1] + count;\n            count += boxes.charAt(i) - \'0\';\n        }\n\t\t\n        for(int i = 0 ; i < n ; i++) {\n            ans[i] = left[i] + right[i];\n        }\n\n        return ans;\n    }\n}\n```
[]