Google | Phone | Find the load of key
Anonymous User
822

Given a String key and it's load, with two operations below:

addLoad(key: String, load: double): void
getLoad(key: String): double

Return the total load for a given key.
Note:
key: [a-zA-Z_][24] (case sensitive)
value: double
Example:

addLoad("Hello", 2.0);
addLoad("Hell", 3.0)
addLoad("He", 4.0);
getLoad("H") --> Should return 2 + 3 + 4 = 9
getLoad("he") --> Should return 0 (as there is no entry for lowercase h)
getLoad("Hell") --> Should return 3 + 2 = 5

Follow up question:
Suppose the key has a time-to-live in secs, how would you go about it.

Comments (6)