Map Sum Pairs
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Implement MapSum, a string-to-integer map that can total values by key prefix.
- MapSum() creates an empty map.
- insert(key, val) sets key to val. If key already exists, its old value is **replaced**, not added to.
- sum(prefix) returns the sum of the values of all keys that start with prefix (a key counts as starting with itself). If no key matches, return 0.
Examples
Constraints
- 1 <= key.length, prefix.length <= 50
- `key` and `prefix` consist of lowercase English letters
- 1 <= val <= 1000
- At most 50 calls to `insert` and `sum`
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.