C++ two solution, Brute force & optimized
\nclass Solution {\npublic:\n    vector<int> minOperations(string boxes) {\n        \n        // brute force   tc->O(N^N)  + sc->O(N)  \n        \n        vecto
```\nclass Solution {\npublic:\n    vector<int> minOperations(string boxes) {\n        \n        // brute force   tc->O(N^N)  + sc->O(N)  \n        \n        vector<int>ans(boxes.length());\n        for(int i = 0 ; i < boxes.length() ; i++){\n            int cnt = 0;\n            for(int j = 0 ; j < boxes.length() ; j++){\n                if(i != j && boxes[j] == \'1\'){\n                    cnt += abs(i-j);\n                }\n            }\n            ans[i] = cnt;\n        }\n        return ans;\n        \n    }\n};\n    \n    // optimized approach   \n\n    // Time: O(N)\n    // Space: O(1)\n        \n        \nclass Solution {\npublic:\n    vector<int> minOperations(string s) {\n        int N = s.size(), sum = 0, right = 0, left = 0;\n        vector<int> ans(s.size());\n        for (int i = 0; i < N; ++i) {\n            if (s[i] == \'1\') sum += i, ++right;\n        }\n        for (int i = 0; i < N; ++i) {\n            ans[i] = sum;\n            if (s[i] == \'1\') --right, ++left;\n            sum += left - right;\n        }\n        return ans;\n    }\n};\n```
['C']