Problem Challenge: Prefix Map

Solve a problem to test and practice your knowledge and understanding of the concept of prefix searching.

Problem Statement

Design a prefix map that must support two operations.

putInMap: This should take a key string and an integer value as the input and map a string key to a given integer value. It should return true if the key does not exist in the map previously; otherwise, it should return false.

getSum: This should take a prefix string as the input and teturns the sum of the integer values of all the keys that have the query as a prefix.

Note that when the putInMap method is called again with the same key but a different value, the value in the map is overwritten.

Example

Sample input

Get hands-on with 1400+ tech skills courses.