Task Row Modifications
Problem statement
Each task owns zero or more integer-valued rows. Process these operations:
["ADD", taskId, rowId, value]adds a new row to a task.["DELETE", taskId, rowId]deletes that row.["MOVE", fromTaskId, toTaskId, rowId]removes the row from the source task and inserts the same row ID and value into the destination task.["SUM", taskId]returns the decimal sum of every row currently owned by that task. An empty or unseen task sums to0.
Return the values produced by SUM operations in order.
Function
runTaskRowModifications(operations: String[][]) → String[]Examples
Example 1
operations = [["ADD","t1","r1","4"],["ADD","t1","r2","7"],["SUM","t1"],["MOVE","t1","t2","r2"],["SUM","t1"],["SUM","t2"],["DELETE","t2","r2"],["SUM","t2"]]return = ["11","4","7","0"]Moving r2 transfers its value from t1 to t2. Deleting it then leaves t2 empty.
Constraints
1 <= operations.length <= 20000.- Task and row IDs are non-empty ASCII strings containing no whitespace.
- Values are decimal integers in
[-10^9, 10^9]. - An
ADDrow ID is absent from its task. - A
DELETEorMOVEsource row exists, and a moved row ID is absent from the destination task. - Every task sum fits a signed 64-bit integer.