Design a Todo List Where users can add tasks, mark them as complete, or get a list of pending tasks. Users can also add tags to tasks and can filter the tasks by certain tags.
Implement the TodoList class:
TodoList() Initializes the object.
int addTask(int userId, String taskDescription, int dueDate, List<String> tags) Adds a task for the user with the ID userId with a due date equal to dueDate and a list of tags attached to the task. The return value is the ID of the task. This ID starts at 1 and is sequentially increasing. That is, the first task’s id should be 1, the second task’s id should be 2, and so on.
List<String> getAllTasks(int userId) Returns a list of all the tasks not marked as complete for the user with ID userId, ordered by the due date. You should return an empty list if the user has no uncompleted tasks.
List<String> getTasksForTag(int userId, String tag) Returns a list of all the tasks that are not marked as complete for the user with the ID userId and have tag as one of their tags, ordered by their due date. Return an empty list if no such task exists.
void completeTask(int userId, int taskId) Marks the task with the ID taskId as completed only if the task exists and the user with the ID userId has this task, and it is uncompleted.
voidcompleteTask(int userId, int taskId){ if(!taskRef.count(userId)) return; if(!taskRef[userId].count(taskId)) return; Task t = taskRef[userId][taskId]; taskRef[userId].erase(taskId); if(taskRef[userId].empty()) taskRef.erase(userId); for(auto& tag : t.tags) { tagRef[userId][tag].erase(t.id); if(tagRef[userId][tag].empty()) tagRef[userId].erase(tag); if(tagRef[userId].empty()) tagRef.erase(userId); } } };
/** * Your TodoList object will be instantiated and called as such: * TodoList* obj = new TodoList(); * int param_1 = obj->addTask(userId,taskDescription,dueDate,tags); * vector<string> param_2 = obj->getAllTasks(userId); * vector<string> param_3 = obj->getTasksForTag(userId,tag); * obj->completeTask(userId,taskId); */