LeetCode 3711, Medium. Topics: Array, Greedy, Heap (Priority Queue). View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 16 parametrized pytest cases, and a playground notebook:
Problem
You are given an integer array transactions, where transactions[i] represents the amount of the i-th transaction:
- A positive value means money is received.
- A negative value means money is sent.
The account starts with a balance of 0, and the balance must never become negative. Transactions must be considered in the given order, but you are allowed to skip some transactions.
Return an integer denoting the maximum number of transactions that can be performed without the balance ever going negative.
Examples
Constraints
- 1 <= transactions.length <= 10^5
- -10^9 <= transactions[i] <= 10^9
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
NeetCode All. Last modified on September 7, 2026