Airbnb questions

Task Management System

AirbnbOnline assessmentMedium

You are building an in-memory task management system as the class SimpleTaskManagementSystem. Every method takes the call's timestamp as its first argument.

Part 1: Tasks and compact JSON

Implement:

  • add_task(timestamp, name, priority) creates a task and returns its id. Ids are task_id_1, task_id_2, and so on, in the order the tasks are created. Two tasks may share a name and a priority.
  • update_task(timestamp, task_id, name, priority) replaces the task's name and priority and returns true, or returns false if no task has that id. The id stays the same.
  • get_task(timestamp, task_id) returns the task as a compact JSON string with the keys name and then priority, for example {"name":"Task 1","priority":5}. There are no spaces outside the strings, and the name is escaped as JSON requires. It returns null if no task has that id.

Ids are case sensitive.

  1. Example 1
    init
    []
    operations
    [["add_task",[1,"Task 1",5]],["add_task",[2,"Task 1",5]],["update_task",[3,"task_id_1","Updated Task 1",4]],["get_task",[4,"task_id_1"]],["get_task",[5,"task_id_2"]],["update_task",[6,"task_id_3","Missing",1]],["get_task",[7,"task_id_3"]],["update_task",[8,"task_id_2","Task 1",5]],["get_task",[9,"task_id_2"]]]
    Output
    ["task_id_1","task_id_2",true,"{\"name\":\"Updated Task 1\",\"priority\":4}","{\"name\":\"Task 1\",\"priority\":5}",false,null,true,"{\"name\":\"Task 1\",\"priority\":5}"]

    Why: Both tasks are named Task 1 with priority 5 and get ids task_id_1 and task_id_2. Updating the first one changes only that task, and get_task returns it as compact JSON. task_id_3 does not exist, so updating or reading it gives false and null. Updating task_id_2 to the values it already has succeeds.

Constraints

  • 1 <= timestamp <= 10^9, and timestamp is larger in every call than in the call before
  • 1 <= len(name) <= 50, and a name uses printable ASCII characters
  • 0 <= priority <= 10^6
  • At most 2000 calls in total
Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question