O(n) and O(n2) both solutions Done
can we do it by recursion if yes\nplease letme know \n\n\nclass Solution {\n    public int[] minOperations(String boxes) {\n        //better approach than brute
can we do it by recursion if yes\nplease letme know \n\n```\nclass Solution {\n    public int[] minOperations(String boxes) {\n        //better approach than brute force \n        //we maintain two arrays left and right and \n        \n        int n = boxes.length();\n        char []ch = boxes.toCharArray();\n        \n        int left[] = new int[n];\n        int count  = ch[0] - \'0\';\n        \n        for(int i=1; i<n; i++){\n            left[i] = left[i-1] + count;\n            count += ch[i] - \'0\';\n        }\n        \n        int right[] = new int[n];\n        count  = ch[n - 1] - \'0\';\n        \n        for(int i=n-2; i>=0; i--){\n            right[i] = right[i+1] + count;\n            count += ch[i] - \'0\';\n        }\n        \n        for(int i=0; i< n;i++){\n            left[i] += right[i];\n        }\n        \n        return left;\n        \n        //this is the brute froce method \n        //TC- O(n2)  and space is O(n) because we are creating new array\n//          int n = boxes.length();\n//         char []ch = boxes.toCharArray();\n//         int []answer = new int[n];\n        \n//         for(int i=0; i<n; i++){\n//             int count = 0;\n//             for(int j=0; j<n ;j++){\n//                 if(i != j && ch[j] == \'1\'){\n//                     count += Math.abs(j-i);\n//                 }\n//                 answer[i] = count;\n//             }\n//         }\n//         return answer;\n    }\n}\n```
['Java']