Magicsheet logo

Design a Todo List

Medium
100%
Updated 6/1/2025

Design a Todo List

1. What is this problem about?

The Design a Todo List interview question asks you to create a system for managing tasks. Users can add tasks with descriptions and deadlines, mark tasks as completed, and query their pending tasks. You also need to support "tags" for tasks and allow users to filter their tasks by these tags. This Design a Todo List coding problem is a multi-dimensional data management challenge requiring efficient retrieval based on multiple criteria.

2. Why is this asked in interviews?

Notion and Bloomberg ask this to see how you organize relational data in an object-oriented way. It tests your proficiency with Design interview patterns, specifically how to handle sorting (by deadline), filtering (by tag), and state management (completed vs. pending). It evaluations your ability to choose the right data structures to keep the most common operations fast.

3. Algorithmic pattern used

  • Task Representation: Create a Task class with fields for id, description, deadline, tags, and isCompleted.
  • User Mapping: Use a Map<Integer, List<Task>> to store tasks for each user.
  • Task Identification: Use a global or per-user counter to assign unique taskId values for O(1)O(1) completion updates.
  • Efficient Queries: For getTasks, you’ll need to filter the user's list and then use a Sorting interview pattern to order by deadline.

4. Example explanation

  1. addTask(user:1, "buy milk", deadline:10, tags:["grocery"]): Task 1 created for User 1.
  2. addTask(user:1, "fix car", deadline:5, tags:["maintenance"]): Task 2 created for User 1.
  3. getTasks(user:1): Returns [Task 2, Task 1] because 5 < 10.
  4. completeTask(user:1, taskId:2): Task 2 is marked completed.
  5. getTasks(user:1): Now only returns [Task 1].

5. Common mistakes candidates make

  • Inefficient Filtering: Checking every task in the system for every query instead of grouping tasks by user first.
  • Missing Tags: Forgetting that a task can have multiple tags, or failing to correctly filter when a tag query is provided.
  • Id Management: Failing to ensure task IDs are unique or trying to use the task's index in a list as its ID (which breaks when tasks are deleted or sorted).

6. Interview preparation tip

Consider using a Priority Queue or a TreeMap if the list of tasks for a user grows very large and getTasks is called frequently. However, for most interview constraints, a List with a filter and sort is the cleanest and most communicative solution.

Similar Questions