TC - O(N) | SC - O(1) | C++ | 100% Faster!
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> minOperations(string boxes) {\n        int n = boxes.size();\n        vector<int> pref(n,0);\n        int ones = boxes[0] == \'1\';\n        for(int i = 1; i < n; ++i){\n            pref[i] = pref[i-1] + ones;\n            if(boxes[i] == \'1\') ones++;\n        }\n        ones = 0;\n        int prev = 0;\n        for(int i = n-1; i >= 0; --i){\n            pref[i] = pref[i] + prev;\n            if(boxes[i] == \'1\'){\n                ones++;\n            }\n            prev += ones;\n        }\n        return pref;\n    }\n};\n```
['C++']