Live-code four features in Instacart's provided Android interview project (Kotlin expected) around the items purchased in a shopping cart.
Asked in the technical phone screen stage. The middle of the post is points-walled, so feature details are not visible. For this algorithmic version, implement the four core behaviors with a pure function: add an item, remove an item, update quantity, and calculate the cart subtotal.
items is a list of dictionaries with id, name, price_cents, and quantity. operations is a list of dictionaries. Return {"items": [...], "total_cents": number} with items sorted by id. An add of an existing item increases its quantity. Removing an unknown item is a no-op. Setting quantity to zero removes the item.
def cart_features(items, operations):