Javascript simple efficient solution
\n/**\n * @param {number[][]} transactions\n * @return {number}\n */\nvar minimumMoney = function(transactions) {\n    let lossProductMaxCashback=0;\n    let pr
```\n/**\n * @param {number[][]} transactions\n * @return {number}\n */\nvar minimumMoney = function(transactions) {\n    let lossProductMaxCashback=0;\n    let profitProductMaxPrice=0;\n    let cost=0;\n    for(let i=0;i<transactions.length;i++){\n        if(transactions[i][0]>transactions[i][1]){//loss product\n            lossProductMaxCashback = Math.max(lossProductMaxCashback,transactions[i][1]);\n            cost += transactions[i][1]-transactions[i][0];\n        }else{\n            profitProductMaxPrice = Math.max(profitProductMaxPrice,transactions[i][0]);\n        }\n    }\n    let ans = -1*(cost  -1*lossProductMaxCashback);\n    if(profitProductMaxPrice-lossProductMaxCashback>0){//After purchasing all loss products. If we need to purchase a profit product which can ask for more money\n        ans += (profitProductMaxPrice-lossProductMaxCashback)\n    }\n    return ans;\n};\n```
['JavaScript']