This is a premium problem. We're working on making it available for free soon.
Explore Free ProblemsSolutions for this premium problem will be available for free soon.
Watch expert explanations and walkthroughs
Jot down your thoughts, approach, and key learnings
Design-style data structure questions like Design a Todo List are common in technical interviews. They test your ability to combine hash maps, arrays, and sorting while designing a clean API and managing multiple constraints.
A combination of hash maps and arrays or lists works well. The hash map quickly groups tasks by user, while lists store individual tasks. Sorting or filtering can be applied when retrieving tasks depending on due dates or tags.
The optimal approach typically uses a hash map keyed by userId to store each user's tasks. Each task stores metadata such as due date, tags, and completion status. Tasks can then be filtered or sorted when retrieved based on requirements like tag filtering or due date ordering.
Tasks can be sorted by due date during retrieval using a sorting algorithm, which takes O(n log n) time. Alternatively, you can maintain tasks in a sorted structure so that retrieval is faster but insertion may become slightly more expensive.