keyMap
) and another for prefix sums (prefixMap
).insert
method:
a. Calculate the value difference (delta
) if the key already exists.
b. Update the value in keyMap
.
c. Update the sums in prefixMap
for each prefix of the key by adding delta
.sum
method:
a. Return the sum associated with the prefix in prefixMap
, or 0 if the prefix does not exist.