Map with Constant-Time Put All
Updated
Problem statement
Process an ordered sequence of operations against an initially empty map from string keys to integer values.
PUT key valueinserts or replaces one key.GET keyreturns the key's current value, orNULLwhen the key is absent.PUT_ALL valuechanges the value of every key currently stored in the map.
The latest applicable PUT or PUT_ALL determines each key's value. A key inserted after a PUT_ALL keeps its newly inserted value until a later operation changes it.
Return one string for every GET operation, in query order. Design PUT_ALL to run in O(1) time.
Function
processMapOperations(operations: String[][]) → String[]Examples
Example 1
operations = [["PUT","a","1"],["PUT","b","2"],["PUT_ALL","5"],["GET","a"],["PUT","b","7"],["GET","a"],["GET","b"],["GET","c"]]return = ["5","5","7","NULL"]The bulk assignment sets both existing keys to 5. The later PUT b 7 changes only b, and c is absent.
Example 2
operations = [["PUT_ALL","9"],["PUT","x","3"],["GET","x"],["PUT_ALL","4"],["GET","x"]]return = ["3","4"]The first bulk assignment affects no keys. Key x is inserted afterward with value 3, then the second bulk assignment changes it to 4.
Constraints
1 <= operations.length <= 100000.- Each operation is exactly one of
PUT,GET, orPUT_ALLwith the required operands. - Keys contain lowercase English letters and have length from
1through20. - Values fit in a signed 32-bit integer.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
- File System Shell CommandsHarvey · ONSITE INTERVIEWHarvey interview questions
- LRU CacheApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
- LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- LRU CacheServiceNow · PHONE SCREEN · ONSITE INTERVIEWServiceNow interview questions
- Rectangle Point Coverage CountsOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Hash Map with Separate ChainingApplied Intuition · ONSITE INTERVIEWApplied Intuition interview questions
- Camel CardsRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Design Authentication ManagerOracle · ONSITE INTERVIEWOracle interview questions