Meta questions

Record Store

MetaPhone screenMedium

Build an in-memory record store as a class RecordStore. A record is addressed by a key and holds named fields, each holding a string value. Every test creates one RecordStore() and runs a sequence of calls, checking every return value; methods that return nothing are checked as None. A test only calls methods introduced so far.

Part 1: Set, get, delete

Implement set(key, field, value), which stores value under field of the record key, overwriting any previous value. get(key, field) returns the stored value, or None if the key or the field does not exist. delete(key, field) removes the field and returns True, or returns False if it does not exist. The empty string is a valid value.

  1. Example 1
    init
    []
    operations
    [["set",["u1","name","ann"]],["get",["u1","name"]],["get",["u1","age"]],["get",["u2","name"]],["set",["u1","name","bob"]],["get",["u1","name"]],["delete",["u1","age"]],["delete",["u1","name"]],["get",["u1","name"]]]
    Output
    [null,"ann",null,null,null,"bob",false,true,null]

    Why: get of an unset field or an unknown key returns None. The second set replaces ann with bob. Deleting age returns False because it was never set; deleting name returns True, after which get returns None.

Constraints

  • 1 <= number of operations <= 2 * 10^5
  • 0 <= len(value) <= 100
  • 1 <= len(key) <= 100
  • 1 <= len(field) <= 100
Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question