2412. Minimum Money Required Before Transactions Hard
1/**
2 * [2412] Minimum Money Required Before Transactions
3 *
4 * You are given a 0-indexed 2D integer array <font face="monospace">transactions</font>, where transactions[i] = [costi, cashbacki].
5 * The array describes transactions, where each transaction must be completed exactly once in some order. At any given moment, you have a certain amount of money. In order to complete transaction i, money >= costi must hold true. After performing a transaction, money becomes money - costi + cashbacki.
6 * Return the minimum amount of money required before any transaction so that all of the transactions can be completed regardless of the order of the transactions.
7 *
8 * Example 1:
9 *
10 * Input: transactions = [[2,1],[5,0],[4,2]]
11 * Output: 10
12 * Explanation:
13 * Starting with money = 10, the transactions can be performed in any order.
14 * It can be shown that starting with money < 10 will fail to complete all transactions in some order.
15 *
16 * Example 2:
17 *
18 * Input: transactions = [[3,0],[0,3]]
19 * Output: 3
20 * Explanation:
21 * - If transactions are in the order [[3,0],[0,3]], the minimum money required to complete the transactions is 3.
22 * - If transactions are in the order [[0,3],[3,0]], the minimum money required to complete the transactions is 0.
23 * Thus, starting with money = 3, the transactions can be performed in any order.
24 *
25 *
26 * Constraints:
27 *
28 * 1 <= transactions.length <= 10^5
29 * transactions[i].length == 2
30 * 0 <= costi, cashbacki <= 10^9
31 *
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/minimum-money-required-before-transactions/
36// discuss: https://leetcode.com/problems/minimum-money-required-before-transactions/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn minimum_money(transactions: Vec<Vec<i32>>) -> i64 {
42
43 }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_2412() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.