Task manager with user quotas and expiring assignments

0
Sign in

Build an in-memory TaskManager in four levels. Each level adds methods to the same class, and you move to the next level only after the current one passes. Every method takes an integer timestamp first. Timestamps strictly increase across calls.

Level 1: tasks

  • add_task(timestamp, name, priority) -> str creates a task and returns a new ID: "task_1", "task_2", and so on, in creation order. Tasks with the same name and priority are still separate tasks.
  • update_task(timestamp, task_id, name, priority) -> bool replaces the task's name and priority. Returns False if the task does not exist.
  • get_task(timestamp, task_id) -> dict | None returns {"name": ..., "priority": ...}, or None for an unknown ID.

Level 2: search

  • search_tasks(timestamp, name_filter, limit) -> list[str] returns the IDs of tasks whose name contains name_filter. Order by priority, highest first. Break ties by creation order, oldest first. Return at most limit IDs.

Level 3: users and assignments

  • add_user(timestamp, user_id, quota) -> bool registers a user who can hold at most quota active assignments. Returns False if the user already exists.
  • assign_task(timestamp, task_id, user_id, finish_time) -> bool gives the task to the user for the window [timestamp, finish_time). The assignment is active until it is completed or until time reaches finish_time. Return False if the task or user is unknown, if finish_time <= timestamp, if the task already has an active assignment, or if the user is at quota.
  • get_user_tasks(timestamp, user_id) -> list[str] returns the task IDs of the user's active assignments, ordered by finish_time and then by assignment order. Unknown user: [].

Level 4: completion and overdue work

  • complete_task(timestamp, task_id, user_id) -> bool completes the task's active assignment if this user holds it. Completion frees a quota slot. An expired assignment cannot be completed.
  • get_overdue_assignments(timestamp, user_id) -> list[str] returns the task IDs of the user's assignments that expired without being completed, in the order they expired. A task that expired twice appears twice.

Constraints

  • Up to 10^5 calls in total. Priorities and times are integers in [0, 10^9]. 0 <= quota <= 10^5.
  • Methods never raise on unknown IDs. They return False, None, or [].

Example 1

add_task(1, "write docs", 3)   -> "task_1"
add_task(2, "write docs", 3)   -> "task_2"
add_task(3, "fix bug", 5)      -> "task_3"
update_task(4, "task_1", "write api docs", 7) -> True
search_tasks(5, "", 10)        -> ["task_1", "task_3", "task_2"]
search_tasks(6, "docs", 1)     -> ["task_1"]

Example 2 (continues Example 1)

add_user(10, "ana", 2)                    -> True
assign_task(11, "task_1", "ana", 20)      -> True
assign_task(12, "task_2", "ana", 15)      -> True
assign_task(13, "task_3", "ana", 40)      -> False   # ana is at quota
assign_task(15, "task_3", "ana", 40)      -> True    # task_2 expired at 15
get_user_tasks(15, "ana")                 -> ["task_1", "task_3"]
complete_task(16, "task_1", "ana")        -> True
get_overdue_assignments(16, "ana")        -> ["task_2"]

Reconstructed from the reported question; details may differ from what interviewers ask.

AnthropicAirbnbCodingMediumLast asked Sep 2026

Sign in to see the worked answer

The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.