Minimum Money Required Before Transactions

Hard

Description

Given array of transactions [cost, cashback], you must complete all in some order. Return minimum starting money to guarantee completion.

Examples

Input:transactions = [[2,1],[5,0],[4,2]]
Output:10
Explanation:

Need 10 to complete.

Input:transactions = [[1]]
Output:1
Explanation:

Minimal case with a single-element matrix.

Input:transactions = [[3,4],[6,1],[2,3]]
Output:11
Explanation:

A minimum of 11 is needed to complete all transactions without the balance ever going negative.

Constraints

  • 1 ≤ transactions.length ≤ 10⁵

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!