Count Tasks by Status
You are given a list of tasks, where each task is represented by a Task structure containing:
- id: An integer identifying the task.
- title: A string representing the task's name.
- status: A TaskStatus enumeration representing its current status.
The TaskStatus enumeration has three possible values: Pending, InProgress, and Completed.
Given a target status, return the number of tasks whose status matches the target. If no tasks match, return 0.
Note: In input , status values are provided as integers: 0 for Pending, 1 for InProgress and 2 for Completed. The driver code converts the input list into a vector<Task> and the integer statuses into TaskStatus enum values before calling countTasks().
Example 1:
Input: tasks = [[1, "Design", 0], [2, "Development", 1], [3, "Testing", 0]], target = 0
Output: 2
Explanation: The target status is Pending (0). Design and Testing are pending, so 2 tasks match.
Example 2:
Input: tasks = [[1, "TaskA", 2], [2, "TaskB", 2], [3, "TaskC", 1]], target = 2
Output: 2
Explanation: Target 2 means Completed. TaskA and TaskB have status 2 and are counted. TaskC has status 1 (InProgress), so it does not match. The result is 2.
Now Your Turn!
Pick the correct output for the given inputInput: tasks = [[1, "Planning", 0], [2, "Review", 1]], target = 2
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 0 <= task.size() <= 104
- 0 <= ids[i] <= 109; duplicate IDs are allowed.
- Each title contains 1 to 100 uppercase or lowercase English letters only.
- 0 <= statuses[i], target <= 2