C++ : O(N) solution in 2 passes
\nclass Solution {\npublic:\n    vector<int> minOperations(string boxes) \n    {\n        vector<int> v;\n        int leftcount=0; //counts number of 1s to the 
```\nclass Solution {\npublic:\n    vector<int> minOperations(string boxes) \n    {\n        vector<int> v;\n        int leftcount=0; //counts number of 1s to the left of current index\n        int leftsum=0; //sum of indexes, i such that boxes[i]=\'1\' to the left of current index\n        int rightsum=0; //sum of indexes, i such that boxes[i]=\'1\' to the right of current index\n        int rightcount=0; //counts number of 1s to the right of current index\n        \n        //initially only rightsum and rightcount will be there for the zeroth index\n        for(int i=0;i<boxes.size();i++)\n        {\n            if(boxes[i]==\'1\')\n            {\n                rightsum+=i;\n                rightcount++;\n            }\n        }\n        \n        for(int i=0;i<boxes.size();i++)\n        {\n            if(boxes[i]==\'1\')\n            {\n                rightcount--;\n                rightsum-=i;\n            }\n            int sum=abs(rightsum-(rightcount*i))+abs(leftsum-(leftcount*i));\n            v.push_back(sum);\n            if(boxes[i]==\'1\')\n            {\n                leftcount++;\n                leftsum+=i;\n            }\n                                                     \n        }\n        return v;\n    }\n};\n```\n\nTime complexity : O(N)\nSpace complexity : O(N) for the vector, but it can be ignored as it is required for the question
['C']