Apply Insert, Update, and Remove Operations to a Keyed Store

Read the full interview experience this question came from →

Quick Overview

Apply insert, update, and remove commands to a keyed store with explicit duplicate and missing-key policies and deterministic final records.

Apply Insert, Update, and Remove Operations to a Keyed Store

Company: Squarepoint

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Onsite

Implement `manage_records(operations)` to apply insert, update, and remove commands to an initially empty keyed record store. The pedagogical policies below make the small record-management task deterministic. An insert rejects an existing key, while update and remove reject a missing key. A rejected operation leaves the store unchanged. The function records the error and continues with later operations; the console does not expose language-specific exception classes. ### Function Signature `manage_records(operations: list[list[str]]) -> dict` ### Input Each operation is a three-string array `[action, key, value]`: - `"insert"`: add `key` with `value`; return status `"inserted"`, or `"exists"` if the key is already present. - `"update"`: replace an existing key's value; return `"updated"`, or `"missing"` if the key is absent. - `"remove"`: delete an existing key; return `"removed"`, or `"missing"` if the key is absent. Its `value` field is always the empty string and is ignored. ### Output Return an object with exactly these keys: - `statuses`: one status string per input operation, in input order. - `records`: the remaining `[key, value]` pairs sorted by key in ascending ASCII lexicographic order. ### Constraints - `0 <= len(operations) <= 100000`. - Every action is one of the three strings defined above. - Each key contains 1 to 40 lowercase ASCII letters or digits. - Each value contains 0 to 100 printable ASCII characters. - The input is valid. Do not mutate it. ### Examples Input: `operations = [["insert","a","first"],["insert","a","second"],["update","a","third"],["remove","b",""]]` Output: `{"statuses":["inserted","exists","updated","missing"],"records":[["a","third"]]}` Input: `operations = [["insert","z",""],["remove","z",""]]` Output: `{"statuses":["inserted","removed"],"records":[]}` Input: `operations = []` Output: `{"statuses":[],"records":[]}`

Overview: Apply insert, update, and remove commands to a keyed store with explicit duplicate and missing-key policies and deterministic final records.

Read the full Squarepoint Software Engineer interview experience this question came from

|Home/Coding & Algorithms/Squarepoint
Squarepoint logo
Squarepoint
Jun 20, 2026
easySoftware EngineerOnsiteCoding & Algorithms
1
0

Implement manage_records(operations) to apply insert, update, and remove commands to an initially empty keyed record store.

The pedagogical policies below make the small record-management task deterministic. An insert rejects an existing key, while update and remove reject a missing key. A rejected operation leaves the store unchanged. The function records the error and continues with later operations; the console does not expose language-specific exception classes.

Function Signature

manage_records(operations: list[list[str]]) -> dict

Input

Each operation is a three-string array [action, key, value]:

  • "insert" : add key with value ; return status "inserted" , or "exists" if the key is already present.
  • "update" : replace an existing key's value; return "updated" , or "missing" if the key is absent.
  • "remove" : delete an existing key; return "removed" , or "missing" if the key is absent. Its value field is always the empty string and is ignored.

Output

Return an object with exactly these keys:

  • statuses : one status string per input operation, in input order.
  • records : the remaining [key, value] pairs sorted by key in ascending ASCII lexicographic order.

Constraints

  • 0 <= len(operations) <= 100000 .
  • Every action is one of the three strings defined above.
  • Each key contains 1 to 40 lowercase ASCII letters or digits.
  • Each value contains 0 to 100 printable ASCII characters.
  • The input is valid. Do not mutate it.

Examples

Input: operations = [["insert","a","first"],["insert","a","second"],["update","a","third"],["remove","b",""]]

Output: {"statuses":["inserted","exists","updated","missing"],"records":[["a","third"]]}

Input: operations = [["insert","z",""],["remove","z",""]]

Output: {"statuses":["inserted","removed"],"records":[]}

Input: operations = []

Output: {"statuses":[],"records":[]}

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...