Short O(N) solution, C++
The problem was quite straightforward.\nJust imagine how many losses you can make before each \'ith\' Transaction. This will be the peak price to do the followi
The problem was quite straightforward.\nJust imagine how many losses you can make before each \'ith\' Transaction. This will be the peak price to do the following transaction and then just find the maximum of all peak transaction amounts.\n\n**Please note some transaction themselves causes loss of money so while calculating the peak you need to remove their loss as loss occurs after the transaction.**\n\n**Loss = Transaction_Amount - Cashback**\n\n```\nclass Solution {\npublic:\n    long long minimumMoney(vector<vector<int>>& transactions) {\n        \n        long long negative_sums = 0;\n        for(auto a : transactions) {\n            negative_sums += max(0ll , (long long)(a[0] - a[1]));\n        }\n        long long ans = 0;\n        for(auto a : transactions) {\n            negative_sums -= max(0ll , (long long)(a[0] - a[1]));\n            ans = max(ans , negative_sums + a[0]);\n            negative_sums += max(0ll ,(long long)(a[0] - a[1]));\n        }\n        return ans;\n    }\n};\n```
['Math', 'C']