← Questions
Move rows between tasks and sum each task
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Notion's practical coding and debugging round, last asked Oct 2025. It tests hash maps, simulation and design.
Each task owns some rows, and every row has an id and an integer value. Process a list of operations that add, delete and move rows, and answer sum queries for a task as you go.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
process(operations: list[list[str]]) -> list[str]— returns the result of everySUM, in order, as decimal strings. -
["ADD", task_id, row_id, value]adds a new row to the task. -
["DELETE", task_id, row_id]removes that row from the task. -
["MOVE", from_task, to_task, row_id]removes the row fromfrom_taskand adds it, with the same id and value, toto_task. -
["SUM", task_id]returns the sum of the task's current rows. A task with no rows, or never seen, sums to"0".
Example
["ADD", "t1", "r1", "4"]
["ADD", "t1", "r2", "7"]
["SUM", "t1"] -> "11"
["MOVE", "t1", "t2", "r2"]
["SUM", "t1"] -> "4"
["SUM", "t2"] -> "7"
["DELETE", "t2", "r2"]
["SUM", "t2"] -> "0"
process(...) -> ["11", "4", "7", "0"]
Constraints
-
1 <= len(operations) <= 20000. - Ids are non-empty ASCII strings with no whitespace. Values are integers in
[-10^9, 10^9]; every sum fits in 64 bits. - Inputs are valid: an added row id isn't already in its task, a deleted or moved row exists in its source task, and a moved row id isn't already in the destination.
Clarifying questions
- Are row ids unique across all tasks, or only within a task?
- Should invalid operations (missing row, duplicate id) raise or be ignored?
- Can a row move to the task it's already in?
- Will there be other queries later, such as the largest row of a task?
What a strong answer covers
- A map from task id to its rows (row id to value) plus a running sum per task, so every operation is O(1).
- Updating both sums on a move, and never recomputing a sum by scanning rows.
- Parsing values as integers once, and returning sums as strings.
- Tests: a move then a delete, sums of unseen tasks, negative values, a task emptied to 0.
Follow-ups
- Add
UPDATE task_id row_id value, andMAX task_idthat returns the task's largest row value. What structure keepsMAXfast under deletes? - Tasks form a tree, and
SUMshould include every subtask's rows. - Support undo of the last operation.
Where it's asked
- Notion · Practical coding and debugging · Last asked Oct 202560 min · Coding or debugging inside a realistic codebase
What it tests
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
