Mutable Table Aggregations
Problem statement
Maintain integer-valued rows across independent tables. Process these operations:
["ADD", tableId, rowId, value]inserts a new row.["UPDATE", tableId, rowId, value]replaces an existing row's value.["DELETE", tableId, rowId]removes an existing row.["QUERY", tableId]returnscount|sum|average|maxfor that table.
Format a non-empty table's average with exactly two digits after the decimal point. For an empty table, return 0|0|0.00|NULL. Return the values produced by QUERY operations in order.
Function
runTableAggregations(operations: String[][]) → String[]Examples
Example 1
operations = [["ADD","docs","r1","10"],["ADD","docs","r2","20"],["QUERY","docs"],["UPDATE","docs","r1","40"],["QUERY","docs"],["DELETE","docs","r2"],["QUERY","docs"]]return = ["2|30|15.00|20","2|60|30.00|40","1|40|40.00|40"]The first query aggregates two rows. Updating r1 changes sum, average, and maximum; deleting r2 leaves one row.
Constraints
1 <= operations.length <= 20000.- Table and row IDs are non-empty ASCII strings containing neither
|nor whitespace. - Values are decimal integers in
[-10^9, 10^9]. - An
ADDrow ID is absent from that table; anUPDATEorDELETErow ID is present. - Every table contains at most
10000rows, and every sum fits a signed 64-bit integer.