FastPrepTask Row Modifications

Task Row Modifications

Notion logoNotion● EasyFULLTIMEONSITE INTERVIEW
Learn

Problem statement

Each task owns zero or more integer-valued rows. Process these operations:

  • ["ADD", taskId, rowId, value] adds a new row to a task.
  • ["DELETE", taskId, rowId] deletes that row.
  • ["MOVE", fromTaskId, toTaskId, rowId] removes the row from the source task and inserts the same row ID and value into the destination task.
  • ["SUM", taskId] returns the decimal sum of every row currently owned by that task. An empty or unseen task sums to 0.

Return the values produced by SUM operations in order.

Function

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

Examples

Example 1

operations = [["ADD","t1","r1","4"],["ADD","t1","r2","7"],["SUM","t1"],["MOVE","t1","t2","r2"],["SUM","t1"],["SUM","t2"],["DELETE","t2","r2"],["SUM","t2"]]return = ["11","4","7","0"]

Moving r2 transfers its value from t1 to t2. Deleting it then leaves t2 empty.

Constraints

  • 1 <= operations.length <= 20000.
  • Task and row IDs are non-empty ASCII strings containing no whitespace.
  • Values are decimal integers in [-10^9, 10^9].
  • An ADD row ID is absent from its task.
  • A DELETE or MOVE source row exists, and a moved row ID is absent from the destination task.
  • Every task sum fits a signed 64-bit integer.

More Notion problems

See Notion hiring insights
public String[] runTaskRowModifications(String[][] operations) {
    // Write your code here.
}
operations[["ADD","t1","r1","4"],["ADD","t1","r2","7"],["SUM","t1"],["MOVE","t1","t2","r2"],["SUM","t1"],["SUM","t2"],["DELETE","t2","r2"],["SUM","t2"]]
expected["11", "4", "7", "0"]
Checking account…