Trains the technique from
LeetCode 1005Maximize Sum Of Array After K NegationsThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A ledger holds one signed adjustment per line in entries; an entry may be negative, zero or positive. An auditor is required to perform exactly flips sign reversals. One reversal picks any single line and replaces its value by its negation.
All flips reversals must be performed. Stopping early is not allowed, and the same line may be picked again on a later reversal, so a line can be reversed any number of times.
Return the largest total the ledger can show once all flips reversals have been performed.
Example 1
Reversing the -6 line three times leaves it at 6, and the ledger reads 4, -1, 3, 6, which totals 12. All three reversals have been used.
Example 2
Reversing the 2 line three times leaves the ledger reading -2, 5, 9, which totals 12. The three reversals are all accounted for.
Example 3
Reversing the -8 line and the -7 line once each leaves the ledger reading 8, 7, -6, -5, which totals 4.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def best_ledger_total(entries: list[int], flips: int) -> int:public int bestLedgerTotal(int[] entries, int flips)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.