🤯 100% TC 100% SC | Understandable python code | Explained
\n\nWe only calculate total loss from strictly loss making transactions.\nFor the last transaction we can either have the biggest loss-making cashback transacti
![image](https://assets.leetcode.com/users/images/9c359646-4da8-4229-aa7f-82725aa47028_1663447483.5845342.png)\n\nWe only calculate total loss from strictly loss making transactions.\n**For the last transaction we can either have the biggest loss-making cashback transaction or the biggest cost of profiting transaction.**\n\n**Our objective is to make as much loss as possible. Remember: before getting CB, we have to bear the cost, hence the last transaction we make matters a lot.**\n\nUpvote if you understood the logic :)\n```\nclass Solution:\n    def minimumMoney(self, transactions: List[List[int]]) -> int:\n        totalLoss = maxCBLosing = maxCostProfiting = 0\n        \n        for cost, cb in transactions:\n            #loss making transactions\n            if cost > cb:\n                totalLoss += cost - cb\n                maxCBLosing = max(maxCBLosing, cb)\n            else:\n                maxCostProfiting = max(maxCostProfiting, cost)\n        \n        return totalLoss + max(maxCBLosing, maxCostProfiting)\n```
['Array', 'Greedy', 'Python']