You are given an initial state and a list of operations that should be applied to it.
Setup
-
The state can be thought of as a mutable object (e.g., a document, a numeric value, an inventory map, or a configuration object).
-
Each operation has a type and parameters (e.g.,
Set(key, value)
,
Increment(key, delta)
,
Delete(key)
, etc.).
Requirements
-
Implement an operation executor
that applies all operations to produce the final state.
-
Use an object-oriented approach consistent with the
Command Pattern
:
-
Each operation should be represented as a command with an
execute(state)
method (and optionally
undo(state)
if discussed).
-
Optimize execution
when possible:
-
Avoid naively applying every operation sequentially if there are opportunities to combine, cancel, reorder, or short-circuit operations
without changing the final result
.
What to discuss
-
Your command abstractions and how new operation types can be added.
-
Correctness constraints for optimization (when reordering/merging is safe).
-
Time/space complexity and edge cases (conflicting operations, no-ops).