Minimum Money Required Before Transactions

HardArraySorting

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:8
Explanation:

Need 10 to complete.

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

With one transaction costing 1 and returning no cashback, 1 unit of starting money is enough.

Input:transactions = [[3,4],[6,1],[2,3]]
Output:4
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 and sharpen your skills for technical interviews.