Skip to main content
All questions
MediumStrings · API Design

Ecommerce Cart Sync

Written by a community member · · 1 attempt · 0% pass

0

Implement a function that synchronizes a user's shopping cart with a dummy RESTful API.

The cart is given as two parallel lists: item_ids[i] is an item id and quantities[i] its quantity. Syncing the cart means sending one update, (item_ids[i], quantities[i]), to the API for each cart entry, in order. The API is simulated: an update succeeds unless its item id appears in failing_ids.

Your task is to apply the cart updates in order. If any update fails, stop immediately and return False. If all updates succeed, return True.

Rules:

  • Process items in the order they appear in the cart
  • If the same item id appears multiple times, send an update for each occurrence
  • Do not mutate the inputs

Examples:

  • sync_cart(['a', 'b'], [2, 1], []) -> True
  • sync_cart(['a', 'b'], [2, 1], ['b']) -> False