In-Memory Object Manager

Asked at AirbnbOnline assessment

Reported by the problem's creator, not verified

You are building an in-memory object manager as the class ObjectManager. Each object, identified by a string id, holds named fields, each with a string value.

Examples

  1. Example 1

    Input: init = [], operations = [["set",["user1","name","alice"]],["set",["user1","nick","ali"]],["get",["user1","name"]],["get",["user1","age"]],["get",["user2","name"]],["set",["user1","name","bob"]],["get",["user1","name"]],["delete_value",["user1","nick"]],["delete_value",["user1","nick"]],["get",["user1","nick"]],["delete_object",["user2"]],["delete_object",["user1"]],["get",["user1","name"]],["delete_object",["user1"]]]

    Output: [null,null,"alice",null,null,null,"bob",true,false,null,false,true,null,false]

    Explanation: set stores two fields on user1, and the second set of name replaces alice with bob. get of a field or an object that was never set is null. delete_value returns true the first time it removes nick and false the second time. delete_object returns false for user2, which has no fields, and true for user1, after which every field of it is gone and a second delete returns false.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.