C++ O(n) Solution without sorting or Binary Search
Approach :\n  Design Logic\n \n  ans = total_spend + other_variable\n   there is two case during transaction \n   case 1: Profit:\n   during profit we are reduc
**Approach :**\n  **Design Logic**\n ```\n  ans = total_spend + other_variable\n   there is two case during transaction \n   case 1: Profit:\n   during profit we are reducing total_spend money but for reducing that money\n   person should have greater pocket money that maximum cost during profit which is part ofother_variable\n   case 2: loss\n   during loss it might be possible that any transaction having huge cashback which reducing the total_spend money from pocket\n   to happen that transaction person should have greater pocket money that that transaction\'s cost but here we already added the loss    to our total_spend money from pocket so the maximum cashback which is reducing total_spend in huge amount that should be part of   other variabl\n    \n   so finally we have two thing in other variable\n   1) maximum cost during profit\n   2) maximum cashback during loss\n   to begin in a safe zone we take maximum of above two as other_variable which being added to total_spend money to give our ans\n```\n   \n **C++ Code:**\n  \n```\n    long long minimumMoney(vector<vector<int>>& transactions) {\n        long long total_spend = 0,cashback=0,cost=0;\n        int n = transactions.size();\n        for(int i=0;i<n;i++){\n           \n            // case 1: Loss\n            if(transactions[i][0]>transactions[i][1]){ \n              total_spend += transactions[i][0]-transactions[i][1];\n             cashback = max(cashback,(long long)transactions[i][1]);\n            }\n             // case 2: profit\n            if(transactions[i][0]<=transactions[i][1]) \n             cost = max(cost,(long long)transactions[i][0]);\n        }\n    return total_spend + max(cost,cashback);\n    }\n};\n```
['C']