FastPrepWorkflow Service Operations

Workflow Service Operations

FurtherAI logoFurtherAI● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Process a finite sequence of workflow-service operations. A workflow has a unique ID and an ordered list of integer transforms. A transform is ADD:x, SUB:x, or MUL:x.

  • ["CREATE", id, step1, step2, ...] stores a non-empty workflow and returns OK, or returns EXISTS without replacing an existing ID.
  • ["EXECUTE", id, payload] applies every stored step in order and returns the final integer as a decimal string, or NOT_FOUND.

Return one result per operation in input order.

Function

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

Examples

Example 1

operations = [["CREATE","w1","ADD:3","MUL:2"],["EXECUTE","w1","4"],["CREATE","w1","SUB:1"],["EXECUTE","missing","7"]]return = ["OK","14","EXISTS","NOT_FOUND"]

Workflow w1 computes (4 + 3) * 2. Its duplicate definition is rejected.

Example 2

operations = [["CREATE","negate","MUL:-1"],["EXECUTE","negate","9"],["EXECUTE","negate","-4"]]return = ["OK","-9","4"]

The same stored transform is reusable across executions and does not mutate workflow state.

Constraints

  • 1 <= operations.length <= 10^5.
  • Each workflow contains between 1 and 50 valid transform steps.
  • Workflow IDs are non-empty strings without :.
  • Payloads, operands, and every intermediate result fit in a signed 64-bit integer.

More FurtherAI problems

See FurtherAI hiring insights
public String[] runWorkflows(String[][] operations) {
    // Write your code here.
}
operations[["CREATE","w1","ADD:3","MUL:2"],["EXECUTE","w1","4"],["CREATE","w1","SUB:1"],["EXECUTE","missing","7"]]
expected["OK", "14", "EXISTS", "NOT_FOUND"]
Checking account…