C++ | EASY TO UNDERSTAND
Please upvote to motivate me in my quest of documenting all leetcode solutions(to help the community). HAPPY CODING:)\nAny suggestions and improvements are alwa
**Please upvote to motivate me in my quest of documenting all leetcode solutions(to help the community). HAPPY CODING:)\nAny suggestions and improvements are always welcome**\n\n**Time complexity: O(n)**\n```\nclass Solution {\npublic:\n    vector<int> minOperations(string boxes) {\n    int n=boxes.length();\n    vector<int> ans(n);\n    vector<int> left(n),right(n);\n    int count=boxes[0]-\'0\';\n    for(int i=1;i<n;i++)\n    {\n        left[i]=left[i-1]+count;\n        count+=boxes[i]-\'0\';\n    }   \n    count=boxes[n-1]-\'0\';\n    for(int i=n-2;i>=0;i--)\n    {\n        right[i]=right[i+1]+count;\n        count+=boxes[i]-\'0\';\n    }\n    for(int i=0;i<n;i++)\n    {\n        ans[i]=left[i]+right[i];\n    }    \n    return ans;    \n    }\n};\n```\n**Time complexity: O(nxn)**\n```\n//1769. Minimum Number of Operations to Move All Balls to Each Box\nclass Solution {\npublic:\n    vector<int> minOperations(string boxes) {\n    int n=boxes.length();\n    vector<int> ans(n);\n    vector<int> pos;\n    for(int i=0;i<n;i++)\n    {\n        if(boxes[i]==\'1\')\n        pos.push_back(i);    \n    }\n    for(int i=0;i<n;i++)\n    {\n        for(int num:pos)\n        {\n            ans[i]+=abs(num-i);\n        }    \n    }  \n    return ans;    \n    }\n};\n```
['C']