optimized and easy c++ solution || T(n): O(n), S(n): O(1)
Intuition\nWe simply have to count number of 1s before and after index i. Using the no. of 1s we can find out no. of operations that would be required to reach 
# Intuition\nWe simply have to count number of 1s before and after index i. Using the no. of 1s we can find out no. of operations that would be required to reach that index i, as no. of operations is the cummilative sum of the no. of ones at the indices before the current index.\n\n# Approach\n    run a loop on input string for calculating the no. of ones before the current index and thus, no. of operations to getting all the balls inside the current index from left side of the current index.\n    run a second loop from right side i.e. last of the input to calculate no. of operations for the no. of ones after the current index or in other words from right side of the current index.\n    you will get the resultant array.\n\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity:O(1)\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> minOperations(string boxes) {\n    int n=boxes.size(),c=0,op=0;\n    vector<int> res(n); \n    //this loop is for no. of operations for the no. of ones before the current index.\n    for (int i=0;i<n;i++) {  \n       res[i] += op;\n       if(boxes[i]==\'1\'){c++;}\n       op+=c;\n    }\n    //this loop is for no. of operations for the no. of ones after the current index.\n    c=0;op=0;\n    for (int i=n-1;i>=0;i--) {\n       res[i]+=op;\n       if(boxes[i]==\'1\'){c++;}\n       op+=c;\n    }\n    return res;\n    }\n};\n```
['C++']