Java O(N) Time Complexity Solution
```\npublic int[] minOperations(String boxes) {\n        int size = boxes.length();\n        int arr[] = new int[size];\n\n        int rightSum = 0;\n        in
```\npublic int[] minOperations(String boxes) {\n        int size = boxes.length();\n        int arr[] = new int[size];\n\n        int rightSum = 0;\n        int onesAtRight = 0;\n        for (int i = 0; i < size; i++) {\n            if(boxes.charAt(i)==\'1\'){\n                onesAtRight++;\n                rightSum+=i;\n            }\n        }\n        int leftSum = 0;\n        int onesAtLeft = 0;\n        for (int i = 0; i < size; i++) {\n            leftSum+=onesAtLeft;\n            if(boxes.charAt(i)==\'1\'){\n                onesAtRight--;\n                onesAtLeft++;\n            }\n            arr[i] = rightSum+leftSum;\n            rightSum-= onesAtRight;\n        }\n        return arr;\n    }\n
['Java']