Katkat

Implement an in-memory SQL-like table

OpenAISoftware Engineer · Onsite

Last updated

This question evaluates implementation skills for an in-memory SQL-like table, focusing on data modeling with nested key-value structures, string handling, efficient lookups, and lexicographic sorting with tie-breaking.

Problem

Implement a simple in-memory database for one table. All values are strings.

Each row is identified by a rowKey (string). Each row contains columns identified by colKey (string).

You must process a sequence of commands and output results for read/query commands.

Supported commands

  1. SET rowKey colKey value
  • Set table[rowKey][colKey] = value.
  1. GET rowKey colKey
  • Output the value if present, otherwise output NULL.
  1. SELECT whereCol whereValue orderByCol
  • Return all rowKeys for rows where table[rowKey][whereCol] == whereValue.
  • Sort the matching rows by the value of orderByCol in ascending lexicographic order.
  • If a row is missing orderByCol, treat its sort value as an empty string "".
  • If multiple rows have the same orderByCol value, break ties by rowKey ascending.
  • Output the resulting rowKeys joined by a single space (or output an empty line if none).

Input/Output format

  • Input: list of commands (one per line).
  • Output:
  • For each GET, print a single line.
  • For each SELECT, print a single line.

Constraints (assume)

  • Up to (2 \times 10^5) commands.
  • Total length of all strings is within reasonable memory limits.