[JavaScript] Easy to follow O(n) - 92ms
js\nfunction minOperations(boxes) {\n  const result = Array(boxes.length).fill(0);\n  \n  // First we make one pass through the array (left to right).\n  // For
```js\nfunction minOperations(boxes) {\n  const result = Array(boxes.length).fill(0);\n  \n  // First we make one pass through the array (left to right).\n  // For each index, we calculate the moves needed to get every\n  // non-empty box on the left of the current index to the current index.\n  \n  // At each i in boxes:\n  //   - add the running sum to result[i]\n  //   - increment the notEmpty box count if the current box is \'1\'\n  //   - add the previously seen notEmpty boxes (including current index) to the runningSum\n  \n  let notEmpty = 0;\n  let runningSum = 0;\n  \n  for (let i = 0; i < boxes.length; ++i) {\n    result[i] += runningSum;\n    if (boxes[i] === \'1\') ++notEmpty;\n    runningSum += notEmpty;\n  }\n  \n  // Make one more pass through the array (right to left).\n  // The operations are identical to the first loop, except that\n  // this pass calculates the moves needed to get every non-empty box\n  // on the right of each index to the current index.\n  \n  notEmpty = 0;\n  runningSum = 0;\n  \n  for (let i = boxes.length - 1; i >= 0; --i) {\n    result[i] += runningSum;\n    if (boxes[i] === \'1\') ++notEmpty;\n    runningSum += notEmpty;\n  }\n  \n  return result;\n}\n```
['JavaScript']