Manage Pending Tasks with Global IDs and Due-Date Ordering

Quick Overview

Manage pending tasks with global sequential IDs, due-date ordering, exact tag filtering and owner-checked completion.

Manage Pending Tasks with Global IDs and Due-Date Ordering

Company: Bloomberg

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Implement `TodoList`, initially with no tasks. - `addTask(userId, taskDescription, dueDate, tags)` adds a pending task and returns a global task ID. IDs start at 1 and increase sequentially across all users. - `getAllTasks(userId)` returns that user's pending task descriptions in increasing due-date order. - `getTasksForTag(userId, tag)` returns that user's pending task descriptions having the exact tag, in increasing due-date order. - `completeTask(userId, taskId)` marks the task complete only if it exists, belongs to that user and is still pending. Otherwise it does nothing. Retrieval returns an empty list when no task matches. ```cpp class TodoList { public: TodoList(); int addTask(int userId, string taskDescription, int dueDate, vector<string> tags); vector<string> getAllTasks(int userId); vector<string> getTasksForTag(int userId, string tag); void completeTask(int userId, int taskId); }; ``` ### Examples **Example 1:** ```text Calls: TodoList(); addTask(2,"Read",20,["Work"]); addTask(2,"Write",10,["Work"]); getAllTasks(2); completeTask(3,1); getTasksForTag(2,"Work"); completeTask(2,2); getAllTasks(2) Returned values: [null,1,2,["Write","Read"], null,["Write","Read"], null,["Read"]] Explanation: The wrong-user completion leaves task 1 pending; completing task 2 removes only Write. ``` **Example 2:** ```text Calls: TodoList(); addTask(1,"A",30,[]); addTask(5,"B",40,["X"]); getAllTasks(1); getTasksForTag(5,"Y") Returned values: [null,1,2,["A"],[]] Explanation: IDs increase across users, and a missing tag matches no task. ``` ### Constraints - `1 <= userId, taskId, dueDate <= 100`; all dueDate values are unique. - `0 <= tags.length <= 100`. - Task descriptions have length 1 through 50. - Tags and tag queries have length 1 through 20. - All strings contain lowercase/uppercase English letters and digits. - At most 100 calls to each method. ### Clarifying Questions - Are task IDs global or per user? Global; each new task gets the next ID. - Do retrieval methods return IDs? No; they return descriptions. - Can a user complete another user's task? No. - Is tag matching case-sensitive? Yes. - Can due dates tie? No; the constraints make them unique. ```hint Check the boundary Check retrieval after an attempted completion by the wrong user. ```

Overview: Manage pending tasks with global sequential IDs, due-date ordering, exact tag filtering and owner-checked completion.

Bloomberg logo
Bloomberg
Source window: 0–6 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Implement TodoList, initially with no tasks.

  • addTask(userId, taskDescription, dueDate, tags) adds a pending task and returns a global task ID. IDs start at 1 and increase sequentially across all users.
  • getAllTasks(userId) returns that user's pending task descriptions in increasing due-date order.
  • getTasksForTag(userId, tag) returns that user's pending task descriptions having the exact tag, in increasing due-date order.
  • completeTask(userId, taskId) marks the task complete only if it exists, belongs to that user and is still pending. Otherwise it does nothing.

Retrieval returns an empty list when no task matches.

class TodoList {
public:
    TodoList();
    int addTask(int userId, string taskDescription, int dueDate, vector<string> tags);
    vector<string> getAllTasks(int userId);
    vector<string> getTasksForTag(int userId, string tag);
    void completeTask(int userId, int taskId);
};

Examples

Example 1:

Calls: TodoList(); addTask(2,"Read",20,["Work"]); addTask(2,"Write",10,["Work"]); getAllTasks(2); completeTask(3,1); getTasksForTag(2,"Work"); completeTask(2,2); getAllTasks(2)
Returned values: [null,1,2,["Write","Read"], null,["Write","Read"], null,["Read"]]
Explanation: The wrong-user completion leaves task 1 pending; completing task 2 removes only Write.

Example 2:

Calls: TodoList(); addTask(1,"A",30,[]); addTask(5,"B",40,["X"]); getAllTasks(1); getTasksForTag(5,"Y")
Returned values: [null,1,2,["A"],[]]
Explanation: IDs increase across users, and a missing tag matches no task.

Constraints

  • 1 <= userId, taskId, dueDate <= 100 ; all dueDate values are unique.
  • 0 <= tags.length <= 100 .
  • Task descriptions have length 1 through 50.
  • Tags and tag queries have length 1 through 20.
  • All strings contain lowercase/uppercase English letters and digits.
  • At most 100 calls to each method.

Clarifying Questions Guidance

  • Are task IDs global or per user? Global; each new task gets the next ID.
  • Do retrieval methods return IDs? No; they return descriptions.
  • Can a user complete another user's task? No.
  • Is tag matching case-sensitive? Yes.
  • Can due dates tie? No; the constraints make them unique.