Practice/Anthropic/Task Management System (Online Assessment)
Task Management System (Online Assessment)
CodingMust
Problem Overview
Your task is to implement a task management system. This problem consists of 4 levels that progressively add complexity:
- Level 1: Implement basic operations to add, update, and retrieve tasks
- Level 2: Add functionality to search and sort tasks based on priority and creation order
- Level 3: Introduce users, time-based task assignment with TTL expiration, and dynamic quota management
- Level 4: Add task completion tracking and historical analysis to identify overdue assignments that expired without completion
Each level is unlocked when the current level is correctly solved.
Important Constraints
- All priority (Level 1) and quota (Level 3) values will be non-negative integers (≥ 0)
- All timestamp (Level 3) and finish_time (Level 3) values will be positive integers representing seconds since the system started
- Time always flows forward, so timestamps are guaranteed to strictly increase as operations are executed
Level 1: Basic Task Management
Description
Implement basic task management functionality including adding new tasks, updating existing tasks, and retrieving task details.
Operations
addTask(timestamp, name, priority) → String
- Adds a new task with the given name and priority
- Returns the unique task ID in the format
"task_id_N" where N is a sequential number starting from 1
- Task IDs are sequentially generated (i.e.,
task_id_2 comes before task_id_10)
- Adding a task with the same name as an existing task is allowed; each task is differentiated by a unique ID
- The timestamp parameter is unused in Level 1 logic but included for API consistency
- The priority parameter is a non-negative integer (≥ 0)
updateTask(timestamp, taskId, name, priority) → boolean
- Updates the name and priority of the task identified by taskId
- Returns
true if the update is successful
- Returns
false if taskId does not exist
getTask(timestamp, taskId) → Optional<String>
- Returns a string representing the task details (name and priority) in JSON format if the task exists
- Returns
Optional.empty() if the task does not exist
- The JSON string must be compact: no whitespace should be added between keys and values, but whitespace within string values (e.g., in name) must be preserved
- Keys must be ordered: first name, then priority
- Tip: You do not need a JSON library. You can manually construct the string.
Example
Level 1 ExampleQueriesExplanationsaddTask(1, "Task 1", 5)returns "task_id_1"addTask(2, "Task 1", 5)returns "task_id_2"; successfully adds another task with the same name and priorityupdateTask(3, "task_id_1", "Updated Task 1", 4)returns true; "task_id_1" is updatedgetTask(4, "task_id_1")returns '{"name":"Updated Task 1","priority":4}'; note: no spacesgetTask(5, "task_id_3")returns Optional.empty(); "task_id_3" does not existupdateTask(6, "task_id_3", "Non-existing Task", 1)returns false; "task_id_3" does not exist