FastPrepTask Management System
Problem · Design

Task Management System

Learn this problem
HardCoinbase logoCoinbaseNEW GRADOA

Problem statement

Implement a task-management service by processing the rows in operations from left to right. The service starts with no tasks. Each operation has a strictly increasing integer timestamp as its second value.

Every task stores a task identifier, text, integer priority, due timestamp, optional assignee, and status. Its status is OPEN, ASSIGNED, or COMPLETED.

  • ["WRITE", timestamp, taskId, text, priority, dueAt] creates a new open, unassigned task. If an unfinished task with that identifier already exists, it replaces the text, priority, and due timestamp while preserving its assignee. A completed task cannot be written again.
  • ["READ", timestamp, taskId] returns [taskId, text, priority, dueAt, assignee, status]. The assignee is the empty string for an open task. A missing task returns an empty row.
  • ["SEARCH", timestamp, query] returns the identifiers of unfinished tasks whose text contains query as a case-sensitive substring.
  • ["LIST", timestamp] returns the identifiers of all unfinished tasks.
  • ["ASSIGN", timestamp, taskId, userId] assigns or reassigns an unfinished task to userId.
  • ["COMPLETE", timestamp, taskId] completes an assigned unfinished task.
  • ["CHECK_OVERDUE", timestamp, userId] returns unfinished tasks assigned to userId whose due timestamp is strictly less than the operation timestamp.

SEARCH and LIST order task identifiers by decreasing priority, breaking ties by task identifier in ascending order. CHECK_OVERDUE orders identifiers by increasing due timestamp, then by task identifier in ascending order.

Return one string row for every operation. A successful state-changing operation returns ["OK"]. A missing task returns ["NOT_FOUND"] for ASSIGN or COMPLETE. An operation on a completed task returns ["NOT_ACTIVE"]. Completing an open task returns ["NOT_ASSIGNED"]. Query operations may return an empty row.

Function

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

Examples

Example 1

operations = [["WRITE","1","t1","Fix login","5","10"],["WRITE","2","t2","Add logs","8","6"],["LIST","3"],["SEARCH","4","Fix"],["ASSIGN","5","t1","u1"],["CHECK_OVERDUE","10","u1"],["CHECK_OVERDUE","11","u1"],["COMPLETE","12","t1"],["CHECK_OVERDUE","13","u1"],["READ","14","t1"]]return = [["OK"],["OK"],["t2","t1"],["t1"],["OK"],[],["t1"],["OK"],[],["t1","Fix login","5","10","u1","COMPLETED"]]

The list places higher-priority t2 first. Task t1 is not overdue at timestamp 10, becomes overdue at 11, and leaves overdue results after completion.

Example 2

operations = [["WRITE","1","a","draft","1","9"],["COMPLETE","2","a"],["ASSIGN","3","a","lee"],["WRITE","4","a","revised","7","12"],["READ","5","a"],["COMPLETE","6","a"],["WRITE","7","a","again","9","20"],["ASSIGN","8","a","sam"]]return = [["OK"],["NOT_ASSIGNED"],["OK"],["OK"],["a","revised","7","12","lee","ASSIGNED"],["OK"],["NOT_ACTIVE"],["NOT_ACTIVE"]]

An update preserves the assignee. Once a is completed, later writes and assignments are rejected.

Example 3

operations = [["READ","1","missing"],["ASSIGN","2","missing","u"],["WRITE","3","b","beta","2","15"],["WRITE","4","a","alpha","2","20"],["WRITE","5","c","gamma","3","15"],["ASSIGN","6","b","u"],["ASSIGN","7","c","u"],["LIST","8"],["CHECK_OVERDUE","16","u"]]return = [[],["NOT_FOUND"],["OK"],["OK"],["OK"],["OK"],["OK"],["c","a","b"],["b","c"]]

LIST sorts by priority and then identifier, while overdue results sort by due timestamp and then identifier.

Constraints

  • 1 <= operations.length <= 100000.
  • Operation timestamps are distinct, strictly increasing integers in [0, 10^9].
  • Each WRITE has timestamp < dueAt <= 10^9 and a priority in [-10^9, 10^9].
  • Task and user identifiers contain 1 to 40 ASCII letters, digits, underscores, or hyphens.
  • Task text and nonempty search queries contain 1 to 80 printable ASCII characters.
  • The total number of task records examined by all SEARCH, LIST, and CHECK_OVERDUE operations is at most 200000.

More Coinbase problems

drafts saved locally
public String[][] processTaskOperations(String[][] operations) {
  // Write your code here
}
operations[["WRITE","1","t1","Fix login","5","10"],["WRITE","2","t2","Add logs","8","6"],["LIST","3"],["SEARCH","4","Fix"],["ASSIGN","5","t1","u1"],["CHECK_OVERDUE","10","u1"],["CHECK_OVERDUE","11","u1"],["COMPLETE","12","t1"],["CHECK_OVERDUE","13","u1"],["READ","14","t1"]]
expected[["OK"], ["OK"], ["t2", "t1"], ["t1"], ["OK"], [], ["t1"], ["OK"], [], ["t1", "Fix login", "5", "10", "u1", "COMPLETED"]]
checking account