FastPrepTask Manager with Timed Assignments

Task Manager with Timed Assignments

Ramp logoRamp● HardFULLTIMEOA
Learn

Problem statement

Process a finite sequence of timestamped operations for an in-memory task manager. Timestamps are strictly increasing. Return one string-list row for every operation.

Tasks

  • ["ADD_TASK", timestamp, name, priority]: create a task and return its ID. IDs are task_id_1, task_id_2, and so on. Equal names and priorities are allowed.
  • ["UPDATE_TASK", timestamp, taskId, name, priority]: replace a task's name and priority. Return a one-element lowercase boolean row.
  • ["GET_TASK", timestamp, taskId]: return one compact JSON string, {"name":"NAME","priority":P}, or an empty row when missing.
  • ["SEARCH_TASKS", timestamp, nameFilter, maxResults]: return up to maxResults IDs whose names contain the case-sensitive filter. Sort by priority descending, then numeric creation order ascending. A nonpositive limit returns an empty row.
  • ["LIST_TASKS_SORTED", timestamp, limit]: return up to limit IDs with the same priority and creation-order sort.

Users and Timed Assignments

  • ["ADD_USER", timestamp, userId, quota]: create a user whose quota is the maximum number of simultaneously active assignments. Return a one-element lowercase boolean row.
  • ["ASSIGN_TASK", timestamp, taskId, userId, finishTime]: create an assignment active on the half-open interval [timestamp, finishTime). It fails when the task or user is missing, finishTime <= timestamp, the user's quota is full, or that task already has an active assignment. A task may be assigned again after its prior assignment completes or expires.
  • ["GET_USER_TASKS", timestamp, userId]: return the user's currently active task IDs in numeric creation order, or an empty row for a missing user.
  • ["COMPLETE_TASK", timestamp, taskId, userId]: complete the matching active assignment and immediately free its quota slot. Return a one-element lowercase boolean row.
  • ["GET_OVERDUE_ASSIGNMENTS", timestamp, userId]: return one task ID for every assignment to that user whose finishTime <= timestamp and which was not completed. Order by finish time ascending and then assignment creation order. A task assigned in multiple expired intervals can appear more than once.

Runner Interface

manageTasks accepts String[][] operations and returns String[][].

Function

manageTasks(operations: String[][]) → String[][]

Examples

Example 1

operations = [["ADD_TASK","1","Alpha","5"],["ADD_TASK","2","Beta","7"],["ADD_TASK","3","Alpha detail","7"],["GET_TASK","4","task_id_1"],["SEARCH_TASKS","5","Alpha","2"],["LIST_TASKS_SORTED","6","2"],["UPDATE_TASK","7","task_id_1","Alpha high","9"],["LIST_TASKS_SORTED","8","3"]]return = [["task_id_1"],["task_id_2"],["task_id_3"],["{\"name\":\"Alpha\",\"priority\":5}"],["task_id_3","task_id_1"],["task_id_2","task_id_3"],["true"],["task_id_1","task_id_2","task_id_3"]]

Search keeps only case-sensitive matches. Priority orders results first, and the numeric task sequence breaks the tie between tasks 2 and 3.

Example 2

operations = [["ADD_TASK","1","One","1"],["ADD_TASK","2","Two","2"],["ADD_USER","3","u","1"],["ASSIGN_TASK","4","task_id_1","u","10"],["ASSIGN_TASK","5","task_id_2","u","8"],["GET_USER_TASKS","9","u"],["GET_USER_TASKS","10","u"],["ASSIGN_TASK","11","task_id_2","u","14"],["COMPLETE_TASK","12","task_id_2","u"],["ASSIGN_TASK","13","task_id_1","u","20"],["GET_USER_TASKS","14","u"]]return = [["task_id_1"],["task_id_2"],["true"],["true"],["false"],["task_id_1"],[],["true"],["true"],["true"],["task_id_1"]]

The first assignment occupies the only quota slot through timestamps below 10. Expiration and completion each free the slot immediately.

Example 3

operations = [["ADD_TASK","1","One","1"],["ADD_TASK","2","Two","1"],["ADD_USER","3","u","2"],["ASSIGN_TASK","4","task_id_1","u","7"],["ASSIGN_TASK","5","task_id_2","u","10"],["COMPLETE_TASK","6","task_id_1","u"],["GET_OVERDUE_ASSIGNMENTS","7","u"],["GET_OVERDUE_ASSIGNMENTS","10","u"],["COMPLETE_TASK","11","task_id_2","u"],["ASSIGN_TASK","12","task_id_2","u","13"],["GET_OVERDUE_ASSIGNMENTS","14","u"]]return = [["task_id_1"],["task_id_2"],["true"],["true"],["true"],["true"],[],["task_id_2"],["false"],["true"],["task_id_2","task_id_2"]]

Completing task 1 before its finish time prevents it from becoming overdue. Task 2 expires twice without completion, so both overdue assignments remain in history.

Constraints

  • 1 <= operations.length <= 10^4.
  • Operation timestamps are distinct, strictly increasing integers in [0, 10^9].
  • Priorities and quotas are integers in [0, 10^9]; limits fit in signed 32-bit integers.
  • Every successful assignment has timestamp < finishTime <= 10^9.
  • Task names have 1 to 80 ASCII letters, digits, spaces, underscores, or hyphens. User IDs have 1 to 40 ASCII letters, digits, underscores, or hyphens.
  • Name filters contain at most 80 printable ASCII characters and may be empty.

More Ramp problems

See Ramp hiring insights
public String[][] manageTasks(String[][] operations) {
  // write your code here
}
operations[["ADD_TASK","1","Alpha","5"],["ADD_TASK","2","Beta","7"],["ADD_TASK","3","Alpha detail","7"],["GET_TASK","4","task_id_1"],["SEARCH_TASKS","5","Alpha","2"],["LIST_TASKS_SORTED","6","2"],["UPDATE_TASK","7","task_id_1","Alpha high","9"],["LIST_TASKS_SORTED","8","3"]]
expected[["task_id_1"], ["task_id_2"], ["task_id_3"], ["{\"name\":\"Alpha\",\"priority\":5}"], ["task_id_3", "task_id_1"], ["task_id_2", "task_id_3"], ["true"], ["task_id_1", "task_id_2", "task_id_3"]]
Checking account…