FastPrepHelpdesk Ticket Processing

Helpdesk Ticket Processing

The Walt Disney Company logoThe Walt Disney Company● MediumFULLTIMEONSITE INTERVIEW

Problem statement

A help desk receives support tickets and processes them one at a time. Run a list of operations on an empty help desk, in order. Every operation returns one string.

  • "SUBMIT id priority": a new ticket named id with the given priority starts waiting. Return "OK". If a ticket with the same id was submitted before, even one that was already processed, ignore this operation and return "DUPLICATE".
  • "PROCESS": pick the waiting ticket that should be handled next, mark it processed, and return its id. Priority 1 is the most urgent and priority 5 is the least urgent, and a more urgent ticket always goes first. Among tickets with the same priority, the one submitted first goes first. If no ticket is waiting, return "EMPTY".
  • "STATUS id": return "WAITING" if the ticket is waiting, "PROCESSED" if it has been processed, or "UNKNOWN" if no ticket with this id was submitted.

Return the results of all operations in order.

Function

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

Examples

Example 1

operations = ["SUBMIT t1 3","SUBMIT t2 1","SUBMIT t3 3","PROCESS","PROCESS","STATUS t1","PROCESS","STATUS t3","PROCESS"]return = ["OK","OK","OK","t2","t1","PROCESSED","t3","PROCESSED","EMPTY"]

Three tickets are submitted. Ticket t2 has priority 1, the most urgent, so it is processed first. Tickets t1 and t3 both have priority 3, and t1 was submitted first, so it goes next. Then t3 is processed. The last PROCESS finds no waiting ticket and returns EMPTY.

Example 2

operations = ["SUBMIT a7 2","SUBMIT a7 5","STATUS a7","STATUS b1","PROCESS","SUBMIT a7 1","STATUS a7"]return = ["OK","DUPLICATE","WAITING","UNKNOWN","a7","DUPLICATE","PROCESSED"]

The second SUBMIT a7 uses an id that was already submitted, so it is ignored and returns DUPLICATE. Ticket a7 is waiting, and b1 was never submitted. After a7 is processed, submitting a7 again is still a duplicate, and its status is PROCESSED.

Example 3

operations = ["PROCESS","SUBMIT x 5","SUBMIT y 4","SUBMIT z 5","PROCESS","PROCESS","PROCESS"]return = ["EMPTY","OK","OK","OK","y","x","z"]

The first PROCESS runs before any ticket exists and returns EMPTY. Then y (priority 4) goes before x and z (priority 5), and x goes before z because it was submitted first.

Constraints

  • 1 <= operations.length <= 2000
  • Each operation is exactly "SUBMIT id priority", "PROCESS", or "STATUS id", with single spaces between parts.
  • Each id has 1 to 10 characters, and each character is a lowercase English letter or a digit.
  • priority is an integer from 1 to 5.

More The Walt Disney Company problems

See The Walt Disney Company hiring insights
Saved
public String[] processTickets(String[] operations) {
    // Write your code here.
}
Checking account…