FastPrepIn-Memory Key-Value Store Operations
Problems/In-Memory Key-Value Store Operations

In-Memory Key-Value Store Operations

OpenAI logoOpenAI● EasyFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source identifies a two-part key-value-store exercise but does not preserve either part's operations, value model, error behavior, specialized features, interface, outputs, or bounds. The judged minimal store contract is an approximately 55% match.

Process a finite ordered sequence of operations on an in-memory key-value store. The store starts empty, keys are strings, and values are signed integers.

  • ["SET", key, value] stores or overwrites the integer value under key and produces no output.
  • ["GET", key] produces VALUE: followed by the current integer, or NULL when the key is absent.
  • ["DELETE", key] removes the key when present and produces true if a key was removed or false otherwise.

Return the outputs from GET and DELETE operations in operation order.

Function

runKeyValueStore(operations: String[][]) → String[]

Examples

Example 1

operations = [["SET","a","1"],["GET","a"],["SET","a","-2"],["GET","a"],["DELETE","a"],["GET","a"],["DELETE","a"]]return = ["VALUE:1","VALUE:-2","true","NULL","false"]

The second SET overwrites a. The first deletion succeeds; afterward a is absent and another deletion returns false.

Example 2

operations = [["GET","missing"],["SET","x","0"],["SET","y","2147483647"],["GET","y"],["DELETE","x"],["GET","x"]]return = ["NULL","VALUE:2147483647","true","NULL"]

A missing lookup returns NULL. Keys are independent, and deleting x does not change y.

Example 3

operations = [["SET","only","-2147483648"]]return = []

A sequence containing only SET operations produces no output.

Constraints

  • 1 <= operations.length <= 100000.
  • Every operation is well formed and has exactly the fields described above.
  • Keys contain from 1 through 50 printable ASCII characters.
  • Every SET value is a signed 32-bit integer written in base 10.

More OpenAI problems

  • Determine the Winner of Three-Card HandsPHONE SCREEN · Seen Nov 2026
  • Sparse Plant Infection SimulationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Light Source Hits: Sample, Compare, and FitPHONE SCREEN · Seen Nov 2026
All OpenAI interview questionsSee OpenAI hiring insights
Saved
class Solution {
    public String[] runKeyValueStore(String[][] operations) {
        // Write your code here.
    }
}
Checking account…