FastPrepMap with Constant-Time Put All
Problems/Map with Constant-Time Put All

Map with Constant-Time Put All

Google logoGoogle● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report describes put, get, and a putAll that takes O(1) time. We defined what happens for a missing key and set a finite number of operations. Our version is about 94% the same as the reported question.

Process an ordered sequence of operations against an initially empty map from string keys to integer values.

  • PUT key value inserts or replaces one key.
  • GET key returns the key's current value, or NULL when the key is absent.
  • PUT_ALL value changes 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, or PUT_ALL with the required operands.
  • Keys contain lowercase English letters and have length from 1 through 20.
  • 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

Interview reports that mention this question

  • Google L3 New Grad SWE Onsite: Three Coding Rounds: 1 Experience

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public String[] processMapOperations(String[][] operations) {
        // Write your code here.
    }
}
Checking account…