Billing Log with Undo and Redo
Reported by candidates from Reddit's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Reddit OA reported in September 2026 hands you a billing amount that starts at 0 and a list of ADD, SET, UNDO and REDO operations. Example 2 is the trap: a SET after an UNDO wipes the redo history, so the final REDO does nothing. It looks like a design problem but it's really two stacks and careful bookkeeping. If you've got an OA invite, expect this shape. If you blank mid-assessment, StealthCoder runs invisibly as a safety net and gives you the stack structure while you keep typing.
The problem
A billing amount starts at 0. Process paired arrays operations and amounts in order: ADD adds the paired amount. SET overwrites the current amount with the paired amount. UNDO reverses the most recently applied ADD or SET, if one exists. REDO reapplies the most recently undone change, if one exists. A new ADD or SET after an undo discards the redo history. Amounts paired with UNDO and REDO are ignored. Return the current amount after every operation. Function billingStatusLog(operations: String[], amounts: long[]) → long[] Examples Example 1 operations = ["ADD","ADD","UNDO","REDO"] amounts = [5,3,0,0] return = [5,8,5,8] Undo removes the second addition and redo reapplies it. Example 2 operations = ["SET","ADD","UNDO","SET","REDO"] amounts = [10,5,0,7,0] return = [10,15,10,7,7] The new SET after undo clears the redo history, so the final redo is a no-op. Constraints 1 <= operations.length == amounts.length <= 100000 Every operation is ADD, SET, UNDO, or REDO. -1000000000 <= amounts[i] <= 1000000000 Every intermediate amount fits in a signed 64-bit integer.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is to store each applied change as a pair of the previous amount and the new amount. Keep an undo stack and a redo stack. ADD or SET records the previous value, applies the change, pushes onto undo, and clears redo. UNDO pops from undo, restores the previous value, and pushes the entry onto redo. REDO pops from redo, reapplies the new value, and pushes back onto undo. Storing the before value means you never have to reverse an operation arithmetically, which matters for SET since you can't invert an overwrite. Common pitfalls are forgetting to clear redo on a new ADD or SET, treating UNDO on an empty stack as an error, and using 32-bit ints when amounts reach 10^9 over 100000 operations. Use a 64-bit type. Everything is O(1) per operation. If you freeze during the live OA, StealthCoder is the hedge that surfaces this two-stack layout fast.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Billing Log with Undo and Redo cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Reddit's OA.
Reddit reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Billing Log with Undo and Redo FAQ
How hard is the Reddit billing log problem really?+
Easy to medium. There's no clever algorithm, just clean state management. Most failures come from missing edge cases like UNDO on empty history or forgetting to clear redo after a new change. If you know the two-stack pattern, it's about fifteen minutes of coding.
What's the core trick?+
Store the previous amount alongside the new amount in each history entry. Then UNDO just restores the old value and REDO reapplies the new one. You never need to invert ADD or SET, which is impossible for SET anyway.
When does redo history get cleared?+
Any new ADD or SET after an undo discards the redo stack. Example 2 shows it: SET 7 after an UNDO means the final REDO has nothing to reapply, so the amount stays 7. UNDO and REDO themselves don't clear it.
Do I need to worry about overflow?+
Yes. Amounts go up to 10^9 and there can be 100000 operations, so sums exceed 32-bit range. Use long in Java or a 64-bit type in your language. The constraints promise intermediate values fit in signed 64-bit.
How do I prepare for this in 48 hours?+
Practice undo/redo style problems with two stacks until the transitions are automatic. Then hand-trace both examples, including the no-op REDO case. Test empty UNDO and empty REDO before submitting. That covers nearly every hidden case.