Skip to main content
All Questions

Implement an integer map with insert, get, addToKey (add x to every key) and addToValue (add y to every value); apply up to 100,000 queries and return the sum of all get results.

Unlock detailed company stats for this questionUpgrade
Implement a map from integers to integers with four operations. insert(x, y) stores value y under key x. get(x) returns the value stored under key x. addToKey(x) increases every key currently in the map by x. addToValue(y) increases every value currently in the map by y. The operations come as two parallel lists: the operation names, and for each one its arguments (two numbers for insert, one number for the other three). Apply them in order and return one number, the total of the values returned by the get calls. There can be up to 100,000 operations, all keys and values stay between -10^9 and 10^9 throughout, and the total needs a 64-bit integer. Example: insert(3, 10), insert(5, 20), addToKey(2), addToValue(-4), get(7), get(5) returns 16 + 6 = 22.

Community answers

No answers contributed by the community yet.

Related courses

Course

Behavioral Interviews: A Practical Guide for Engineers

Get offers at the level you deserve. Prep for senior+ behavioral interviews at FAANG and Tier-1 companies. Made with staff and principal engineers from Meta, Netflix, Google, and more. Avoid downleveling, elevate past projects, and stop sounding like a robot.

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.