Map Sum Pairs

Design a MapSum object that stores integer values by lowercase keys. The constructor creates an empty map. insert(key, value) replaces the value currently associated with key, rather than adding to it. sum(prefix) returns the sum of values for all stored keys beginning with prefix at the moment of the call. Constructors and insert return null through the design dispatcher, while each sum returns its numeric result.

  • Operations: MapSum(), insert("apple", 3), sum("ap"), insert("app", 2), sum("ap")
  • Output: [null, null, 3, null, 5]
Examples
Input: ["insert","apple","3","sum","ap","insert","app","2","sum","ap","sum","p"]
Output: 8
Hints

Map Sum Pairs

Design a `MapSum` object that stores integer values by lowercase keys. The constructor creates an empty map. `insert(key, value)` replaces the value currently associated with `key`, rather than adding to it. `sum(prefix)` returns the sum of values for all stored keys beginning with `prefix` at the moment of the call. Constructors and `insert` return `null` through the design dispatcher, while each `sum` returns its numeric result.