Billing Log with Undo and Redo
Updated
Problem statement
A billing amount starts at 0. Process paired arrays operations and amounts in order:
ADDadds the paired amount.SEToverwrites the current amount with the paired amount.UNDOreverses the most recently appliedADDorSET, if one exists.REDOreapplies 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, orREDO. -1000000000 <= amounts[i] <= 1000000000- Every intermediate amount fits in a signed 64-bit integer.
More Reddit interview questions
- Straight-Line Word SearchPHONE SCREEN · Seen Nov 2026
- Filter Undesired Comments and Their DescendantsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Tennis Game and Set ScoringPHONE SCREEN · Seen Oct 2026
- Shortest Word Transformation SequencePHONE SCREEN · Seen Sep 2026
- Validate a Single-Letter Word SequencePHONE SCREEN · Seen Sep 2026
- Chatter Message WindowPHONE SCREEN · Seen Jul 2026
- Reconstruct Billing StatusONSITE INTERVIEW · Seen Jun 2026
Similar questions at other companies
- Stack with Constant-Time Middle QueriesAmazon · PHONE SCREEN
- Adding Stack 2.0IMC Trading · OAIMC Trading interview questions
- Customer Bootstrap APIDoorDash · PHONE SCREEN · ONSITE INTERVIEWDoorDash interview questions
- Generic Stack Operation SequenceArista Networks · PHONE SCREEN · ONSITE INTERVIEWArista Networks interview questions
- Asteroid CollisionSiemens · PHONE SCREEN
- Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Multiline Text Editor with Cursor MovementDatologyAI · PHONE SCREEN
- Count Events in Rolling Minute WindowsMeta · PHONE SCREENMeta interview questions
- Process On-Call Routing OperationsOpenAI · PHONE SCREENOpenAI interview questions