Apply a List of Operations to a State

Asked at Oracle · Coding Questions · Difficulty: Medium · Last asked Feb 3, 2026

Build a small engine that applies a list of changes to an inventory. A `State` holds item quantities and string metadata. Each change is an object (a command) with its own `apply` method, so the driver is a plain loop that never branches on the kind of change. Two follow-ups then ask which changes may be swapped and how to shorten a list of changes before it runs.

Loading the problem…