C++ O(N)
\nclass Solution {\npublic:\n    vector<int> minOperations(string boxes) {\n       \n        int ah=0;//ahead\n        int be=0;//behind\n        \n        int 
```\nclass Solution {\npublic:\n    vector<int> minOperations(string boxes) {\n       \n        int ah=0;//ahead\n        int be=0;//behind\n        \n        int n=boxes.size();\n         vector<int> res(n);\n        for(int i=0;i<n;i++)\n        {\n            if(boxes[i]==\'1\')\n            {\n                ah++;\n                res[0]+=i;\n            }\n        }\n        if(boxes[0]==\'1\')\n        {\n            ah--;\n            be++;\n        }\n        \n        for(int i=1;i<n;i++)\n        {\n            res[i]+= res[i-1]-ah+be;\n             if(boxes[i]==\'1\')\n        {\n            ah--;\n            be++;\n        }\n        }\n        return res;\n    }\n};\n```
['C']