Java simple O(n) solution with 99% faster
```\nclass Solution {\n    public int[] minOperations(String boxes) {\n        int[] fromR = new int[boxes.length()];\n        int[] fromL = new int[boxes.lengt
```\nclass Solution {\n    public int[] minOperations(String boxes) {\n        int[] fromR = new int[boxes.length()];\n        int[] fromL = new int[boxes.length()];\n        int oneR = 0, oneL = 0;\n        if(boxes.charAt(0) == \'1\'){\n            oneL++;\n        }\n        for(int i=1; i<boxes.length(); i++){\n            fromL[i] = fromL[i-1] + oneL;\n            if(boxes.charAt(i) == \'1\') oneL++;\n        }\n        if(boxes.charAt(boxes.length() -1 ) == \'1\')\n            oneR++;\n        for(int i = boxes.length() - 2; i >= 0; i-- ){\n            fromR[i] = fromR[i+1] + oneR;\n            if(boxes.charAt(i) == \'1\') oneR++;\n        }\n        for(int i=0; i<boxes.length(); i++){\n            fromL[i] += fromR[i];\n        }\n        return fromL;\n    }\n}
['Array', 'Dynamic Programming', 'Java']