Implement the MapSum class: 1. MapSum() Initializes the MapSum object. 2. void insert(String key, int val) Inserts the key-val pair into the map. If the key already existed, the original key-value pair will be overridden to the new one. 3. int sum(string prefix) Returns the sum of all the pairs' value whose key starts with the prefix.
Input Format
Input is managed for you
Output Format
Output is managed for you
Constraints
1. 1 <= key.length, prefix.length <= 50 2. key and prefix consist of only lowercase English letters. 3. 1 <= val <= 1000
Notice
Try First, Check Solution later
1. You should first read the question and watch the question video.2. Think of a solution approach, then try and submit the question on editor tab.3. We strongly advise you to watch the solution video for prescribed approach.Example
Input
apple 3 ap app 2 apple 2 ap exit
Output
3 4