</>OfferRetriever
DashboardDiscuss
NEW

Spring Hire Sale

Limited Time Deal: Unlock all premium questions for over 30% off

$10.42$7.08

08

:

04

:

51

:

21

Get this deal
Back to Dashboard

OA[CodeSignal] In-Memory Database

Hard

Description

Implement a simplified in-memory database that supports record manipulation with various operations. The system should handle basic CRUD operations, conditional updates, filtering, TTL (Time-To-Live), and point-in-time queries.

The database operates on records, where each record is identified by a unique string key. Each record contains multiple field-value pairs, where both field names and values are strings.

All operations include a timestamp parameter (stringified milliseconds). Timestamps are strictly increasing and unique, ranging from 1 to 10^9.

Operations

Level 1: Basic Operations

SET <timestamp> <key> <field> <value>

Insert or update a field-value pair in the record associated with key. If the field exists, replace its value. If the record does not exist, create it.

Returns: Empty string ""

COMPARE_AND_SET <timestamp> <key> <field> <expectedValue> <newValue>

Update field to newValue only if its current value equals expectedValue. If key or field does not exist, or if values don't match, the operation is ignored.

Returns: "true" if updated, "false" otherwise

COMPARE_AND_DELETE <timestamp> <key> <field> <expectedValue>

Delete field only if its current value equals expectedValue. If key or field does not exist, or if values don't match, the operation is ignored.

Returns: "true" if deleted, "false" otherwise

GET <timestamp> <key> <field>

Retrieve the value of field in the record associated with key.

Returns: The value as a string, or empty string "" if not found


Level 2: Filtering (Additional Operation)

...