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 aretask_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 returnstrue, or returnsfalseif 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 keysnameand thenpriority, for example{"name":"Task 1","priority":5}. There are no spaces outside the strings, and the name is escaped as JSON requires. It returnsnullif no task has that id.
Ids are case sensitive.
- 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 1with priority 5 and get idstask_id_1andtask_id_2. Updating the first one changes only that task, andget_taskreturns it as compact JSON.task_id_3does not exist, so updating or reading it givesfalseandnull. Updatingtask_id_2to the values it already has succeeds.
Constraints
1 <= timestamp <= 10^9, andtimestampis larger in every call than in the call before1 <= len(name) <= 50, and a name uses printable ASCII characters0 <= priority <= 10^6- At most
2000calls in total
Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.