💥 Beats 100% on memory, 75% on runtime [EXPLAINED]
IntuitionDetermine the minimum amount of money required to start with in order to complete all transactions, no matter the order. For each transaction, if the c
# Intuition
Determine the minimum amount of money required to start with in order to complete all transactions, no matter the order. For each transaction, if the cost is greater than the cashback, you'll need extra money to cover that difference.

# Approach
Track the total extra money needed (sumDiff) when the cost exceeds the cashback, and find the maximum of the cost and cashback to ensure you have enough money for the toughest transaction.

# Complexity
- Time complexity:
O(n), where n is the number of transactions, since we go through the list of transactions once.

- Space complexity:
O(1), as we only use a few variables to store intermediate values.

# Code
```typescript []
function minimumMoney(transactions: number[][]): number {
        let sumDiff = 0;
        let maxTerm = 0;

        for (const transaction of transactions) {
            const [cost, cashback] = transaction;

            if (cost > cashback) {
                sumDiff += cost - cashback;
                maxTerm = Math.max(maxTerm, cashback);
            } else {
                maxTerm = Math.max(maxTerm, cost);
            }
        }

        return sumDiff + maxTerm;
}

```
['TypeScript']