Intution explained
\n\n\nclass Solution {\npublic:\n        \n        long long costSpent=0;\n        long long cost=0;\n        long long cashBack=0;\n\n        for(int i=0;i<tra
```\n\n\nclass Solution {\npublic:\n        \n        long long costSpent=0;\n        long long cost=0;\n        long long cashBack=0;\n\n        for(int i=0;i<transactions.size();++i){\n            \n            if(transactions[i][0]>transactions[i][1]){\n                costSpent+=(transactions[i][0]-transactions[i][1]);\n                cashBack=max(cashBack,(long long)transactions[i][1]);\n            }\n            else{\n                cost=max(cost,(long long)transactions[i][0]);\n            }\n        }\n        return costSpent+max(cost,cashBack);\n        \n    }\n};\n```\n Here we want minimum money to start with so that we can finish transactions in any order we like.\n So we can consider two scenarios, first is when we will check for all the positive transactions ,i.e in which we need to spend more than what we get.\n This is clear that this much money is the least that we must have . But wait,are we missing on something??\nYes the second thing that we want to keep in account is that we must also include in our sum which can be either \n1. max of cost in case of negative transactions\n 2. max of cashbacks in case of  positive transactions .\n and at the end we need to include max of both of previously calculated value\n with the sum of positive transaction amount that we mentioned in line 1.\n  return the sum at the end; \n        \n   for example consider this: [[3,9],[0,4],[7,10],[3,5],[0,9],[19,13],[7,4],[0,0],[3,3],[8,0]]\n    here in this case we can see that costSpent=17;\n    but one of the transactions requires more than 17 , i.e if this has to complete first then we will fell short of money.\n so this is why we need to keep track of how much more money want despite of costSpent amount which is done by keeping track of max cashBack in case of positive transactions \nand max Cost in case of negative transactions.\nIf the idea is still not clear just revisit the post again and do a dry-run on some testcases.\n**Time Complexity: O(N)\n   Space Complexity: O(1)**\n```\n\n```
['C']