Map Sum Pairs
Explore how to design and implement a MapSum class that inserts key-value pairs and computes the total sum of values for keys sharing a prefix. Understand trie usage to manage strings efficiently and practice solving this common coding interview pattern.
We'll cover the following...
We'll cover the following...
Statement
Design a data structure that supports the following operations:
Insert a key-value pair:
Each key is a string, and each value is an integer.
If the key already exists, update its value to (overriding the previous value).
Return the prefix sum:
Given a string,
prefix, return the total sum of all values associated with keys that start with this prefix.
To accomplish this, implement a class MapSum:
Constructor: Initializes the object.
void insert (String key, int val): ...