Easy C++ code with **Time Complexity**: O(n)
\n\n\nvector minOperations(string boxes) {\n        vectorans;\n        \n        int sum=0;\n        int count=0;\n        int ext=0;\n        for(int i=boxes.
\n\n\nvector<int> minOperations(string boxes) {\n        vector<int>ans;\n        \n        int sum=0;\n        int count=0;\n        int ext=0;\n        for(int i=boxes.size()-1;i>=0;i--){\n            if(boxes[i]==\'1\'){\n                ext++;\n                  sum+=(boxes.size()-(i+1));\n            }\n              \n        }\n        int left=0;\n          for(int i=boxes.size()-1;i>=0;i--){\n            if(boxes[i]==\'1\')\n            {\n                sum-=(boxes.size()-(i+1));\n                ext--;\n                ans.push_back(sum+count-(ext*(boxes.size()-(i+1))));\n                left++;\n            }\n              else{\n                    \n                  ans.push_back(sum+count-(ext*(boxes.size()-(i+1))));\n                   }\n              count+=left;\n        }\n        reverse(ans.begin(),ans.end());\n        return ans;\n        \n    }
[]