FastPrepMutable Record Store with Error Results

Mutable Record Store with Error Results

Squarepoint Capital logoSquarepoint Capital● EasyNEW GRADONSITE INTERVIEW
Learn

Problem statement

Process commands over string records keyed by id:

  • INSERT id value creates a missing record.
  • UPDATE id value changes an existing record.
  • REMOVE id deletes an existing record.
  • GET id reads an existing value.

Every successful mutation emits OK. A duplicate insert or any missing-id update, remove, or get emits ERROR. GET otherwise emits the value. Return all results in command order.

Function

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

Examples

Example 1

operations = ["INSERT a one","GET a","UPDATE a two","GET a","REMOVE a","GET a"]return = ["OK","one","OK","two","OK","ERROR"]

The record moves through insert, update, removal, and missing read.

Example 2

operations = ["INSERT x 1","INSERT x 2","GET x"]return = ["OK","ERROR","1"]

A duplicate insert does not overwrite.

Example 3

operations = ["UPDATE q 9","REMOVE q"]return = ["ERROR","ERROR"]

Both operations require an existing record.

Constraints

  • 1 <= operations.length <= 10^5.
  • Ids and values are nonempty strings without spaces.
  • Commands are valid and use only the four documented operations.

More Squarepoint Capital problems

See Squarepoint Capital hiring insights
public String[] recordStore(String[] operations) {
    // Write your solution here.
}
operations["INSERT a one","GET a","UPDATE a two","GET a","REMOVE a","GET a"]
expected["OK", "one", "OK", "two", "OK", "ERROR"]
Checking account…