Easy C++ O(n) Time & O(1) Space Solution
\nclass Solution {\npublic:\n    vector<int> minOperations(string boxes) {\n        vector<int> res;\n        int left = 0; // Distance of all \'1\' on the left
```\nclass Solution {\npublic:\n    vector<int> minOperations(string boxes) {\n        vector<int> res;\n        int left = 0; // Distance of all \'1\' on the left side\n\t\tint left_cnt = 0; // Number of \'1\' on the left side\n        int right = 0; // Distance of all \'1\' on the right side\n        int right_cnt = 0; // Number of \'1\' on the right side\n\t\t// Calculate the \'1\' count and sum distance at index \'-1\'\n        for (int i=0; i<boxes.size(); ++i) {\n            if (boxes[i] == \'1\') {\n                right += i + 1;\n                ++right_cnt;\n            }\n        }\n        for (int i=0; i<boxes.size(); ++i) {\n\t\t\t// When i -> i+1, all left \'1\' distances become distance + 1,\n\t\t\t// and all right distances become distance - 1.\n            left += left_cnt;\n            right -= right_cnt;\n            if (boxes[i] == \'1\') {\n                ++left_cnt;\n                --right_cnt;\n            }\n            res.push_back(left + right);\n        }\n        return res;\n    }\n};\n```
['C']