Problem · Array
Billing Log with Undo and Redo
Learn this problemProblem 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.