AGENT CALL · Mokabla · get_question
request ag_a9b8589baf37

Decision

Allowed   R6 · Within policy

input
{"company":"noon","question":"cart-merge"}

Result

{
  "slug": "cart-merge",
  "title": "Cart Merge",
  "difficulty": "easy",
  "tags": [
    "coding",
    "phone",
    "swe",
    "backend"
  ],
  "is_free": true,
  "locked": false,
  "frequency": 0.231,
  "last_reported_at": "2026-02-22T16:54:37.879762Z",
  "url": "https://www.mokabla.com/en/c/noon/cart-merge",
  "agent": {
    "page": "https://www.mokabla.com/agent/en/c/noon/cart-merge",
    "question": "https://www.mokabla.com/agent/_call/get_question?company=noon&question=cart-merge"
  },
  "company": {
    "slug": "noon",
    "name_en": "noon"
  },
  "body_md": "## Problem\nA shopper adds items as a guest, then logs in and already has a saved cart. Merge the two. Each cart is a list of `{sku, qty}` in the order items were added. Rules:\n\n- Same `sku` in both: quantities add up, capped by `max_qty[sku]` (default cap `10` if the SKU is not in the map).\n- Keep the **user** cart's order first, then guest-only SKUs in guest order.\n- Drop any line whose final quantity is `0`.\n- SKUs listed in `out_of_stock` are dropped entirely and returned separately so the UI can show a message.\n\nReturn `(merged, dropped)`.\n\n## Examples\n**Example 1**\n```\nuser  = [{A, 2}, {B, 1}]\nguest = [{B, 3}, {C, 1}]\nmax_qty = {B: 3}\n```\n→ merged `[{A, 2}, {B, 3}, {C, 1}]`, dropped `[]`. `B` would be 4 but is capped at 3.\n\n**Example 2**\n```\nuser  = [{A, 1}]\nguest = [{A, 0}, {D, 2}]\nout_of_stock = {D}\n```\n→ merged `[{A, 1}]`, dropped `[D]`.\n\n## Constraints\n- Up to `200` lines per cart; SKUs are strings; `0 <= qty <= 1000`.\n- Single pass per cart is enough; do not go quadratic on SKU lookup.\n- Be explicit about which cart wins on ties in ordering.\n\n## What they look for\nAn ordered map (or dict + list) so order is stable, the cap applied **after** summing, and the out-of-stock check done before the cap so the dropped list is accurate. The follow-up is usually about what happens if the user's cart changed on another device in between: version numbers or last-write-wins, and where that decision lives.",
  "follow_ups_md": "- The saved cart was modified on another device 5 seconds ago: how do you avoid overwriting it?\n- Prices changed between add and merge: whose price wins?\n- Guest cart lives in a cookie: size limits and tampering.",
  "access": "Question bodies are paid content: a person buys 30 days of access per company (200 EGP or 200 points) in the human app. Agents get titles, tags and difficulty; bodies only for free questions."
}

Navigate (pre-filled links you can follow)