FastPrepTodo Task Manager Operations

Todo Task Manager Operations

Cisco logoCisco● MediumFULLTIMEONSITE INTERVIEW
Learn

Problem statement

Process a finite ordered sequence of todo-task operations. Each task has a unique integer ID, a title, and one status: new, pending, or resolved.

  • ["CREATE", id, title] creates a task with status new and returns OK, or EXISTS if the ID is already present.
  • ["READ", id] returns id|title|status, or NOT_FOUND.
  • ["UPDATE_TITLE", id, title] and ["UPDATE_STATUS", id, status] return OK on success or NOT_FOUND. An invalid status returns INVALID_STATUS without changing the task.
  • ["DELETE", id] removes the task and returns OK, or NOT_FOUND.

Return one result for every operation in input order.

Function

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

Examples

Example 1

operations = [["CREATE","7","Ship release"],["READ","7"],["UPDATE_STATUS","7","pending"],["READ","7"],["DELETE","7"],["READ","7"]]return = ["OK","7|Ship release|new","OK","7|Ship release|pending","OK","NOT_FOUND"]

The task is created, updated, read in both states, deleted, and then no longer exists.

Example 2

operations = [["CREATE","1","Draft"],["CREATE","1","Again"],["UPDATE_STATUS","1","closed"],["READ","1"]]return = ["OK","EXISTS","INVALID_STATUS","1|Draft|new"]

A duplicate create and an invalid status leave the original task unchanged.

Constraints

  • 1 <= operations.length <= 10^5.
  • Task IDs are non-negative 32-bit integers encoded as decimal strings.
  • Titles are non-empty and do not contain |.
  • Every operation has the exact arity described above.

More Cisco problems

See Cisco hiring insights
public String[] manageTasks(String[][] operations) {
    // Write your code here.
}
operations[["CREATE","7","Ship release"],["READ","7"],["UPDATE_STATUS","7","pending"],["READ","7"],["DELETE","7"],["READ","7"]]
expected["OK", "7|Ship release|new", "OK", "7|Ship release|pending", "OK", "NOT_FOUND"]
Checking account…