[Python 3] ONE-LINER, O(n)
It is super easy: \n the second (sum) part takes the sum of the total cost of the transaction (cost - cashback, if it makes sense to include this transaction, i
It is super easy: \n* the second (sum) part takes the sum of the total cost of the transaction (cost - cashback, if it makes sense to include this transaction, i.e. cost > cashback).\n* The first term (max) searches for the most costly transacion to make as the last one (only cost operation, no cashback taken). To make the last transaction you need to either choose which `cost - back` from the second part of the equation will be cancelled and replaced with `cost - (cost - back) ` i.e. `back` only, or if it was not included in the sum part (i.e. `cost <= back`) then add `cost` for the last transaction. Whether you take `cost` or `back` is controlled by `min`.\n```\nreturn max([min(t) for t in transactions]) + sum([cost - back for cost, back in transactions if cost > back])\n```
[]