📌📌 96% faster || Greedy Approach || Well-Explained || For-Beginners 🐍
IDEA :\nHere, we can create prefix and postfix array of size n\2 to store the number of ones before (or after) the index and also information of the number of c
## IDEA :\nHere, we can create prefix and postfix array of size n\\*2 to store the number of ones before (or after) the index and also information of the number of costs required to collect all the ones at previous index.\n**For Example :**  \n\'\'\'\n\n\tstring given  =   "  0       0       1      0      1      1 "\n\tpostfix array =   [[3,11], [3,8],  [2,5], [2,3], [1,1], [0,0]]        # (starting the array from right for computation).\n\tprefix array  =   [[0,0],  [0,0],  [0,0], [1,1], [1,2], [2,4]]        # (starting the array from left for computation).\n\t\n\tTake prefix array for explaination:\n\t[0,0]    -> 0 number of \'1\' is present left to that position and 0 number of cost required to collect all 1\'s left to it.\n\t[0,0]    -> 0 number of \'1\' is present left to that position and 0 number of cost required to collect all 1\'s left to it.\n\t[0,0]    -> 0 number of \'1\' is present left to that position and 0 number of cost required to collect all 1\'s left to it.\n\t[1,1]    -> 1 number of \'1\' is present left to that position and 1 number of cost required to collect all 1\'s left to it.\n\t[1,2]    -> 1 number of \'1\' is present left to that position and 2 number of cost required to collect all 1\'s left to it.\n\t[2,4]    -> 2 number of \'1\' is present left to that position and 4 number of cost required to collect all 1\'s left to it.\n\t\n\tFormula used to calculate:\n\tpre[i][0] = boxes[i-1] + pre[i-1][0]\n    pre[i][1] = boxes[i-1] + pre[i-1][0] + pre[i-1][1]\n\n### CODE :\n\'\'\'\n\n\tclass Solution:\n    def minOperations(self, boxes: str) -> List[int]:\n        \n        n = len(boxes)\n        boxes = [int(i) for i in boxes]\n        pre = [[0,0] for i in range(n)]\n        post= [[0,0] for i in range(n)]\n        \n        for i in range(1,n):\n            pre[i][0] = boxes[i-1] + pre[i-1][0]\n            pre[i][1] = boxes[i-1] + pre[i-1][0] + pre[i-1][1]\n        \n        for i in range(n-2,-1,-1):\n            post[i][0] = boxes[i+1] + post[i+1][0]\n            post[i][1] = boxes[i+1] + post[i+1][0] + post[i+1][1]\n        \n        for i in range(n):\n            boxes[i] = pre[i][1]+post[i][1]\n        \n        return boxes\n\n### Thanks & upvote if you like the idea!!\uD83E\uDD1E
['Python', 'Python3']