Problempromotion feed

Session: Sign in to solve

Solution.txt

Promotion Feed

Problem

Design PromotionFeed to collect offers and advertisements from named sources in one ordered feed for internal consumers.

Requirements

  • Empty feed. A new feed returns an empty array from listPromotions.
  • Offer normalization. ingestOffer appends exactly {source, sourceId: offerId, kind: "offer", text: description}.
  • Advertisement normalization. ingestAdvertisement appends exactly {source, sourceId: advertisementId, kind: "advertisement", text: message}.
  • Complete listing. listPromotions returns every record appended through either ingestion method.
  • Receipt order. Returned records preserve the exact global ingestion order across sources and promotion kinds.

API

SignatureReturnsBehavior
PromotionFeed()A new PromotionFeedCreates an empty feed.
ingestOffer(source, offerId, description)NothingAdds one offer supplied by source.
ingestAdvertisement(source, advertisementId, message)NothingAdds one advertisement supplied by source.
listPromotions()An array of objectsReads the canonical records collected so far.

Each returned object has exactly four string fields: source, sourceId, kind, and text.

Examples

StepOperationResult
1ingestOffer("restaurant-app", "offer-7", "20% off")Nothing
2ingestAdvertisement("partner-network", "ad-3", "Free delivery")Nothing
3listPromotions()[{source: "restaurant-app", sourceId: "offer-7", kind: "offer", text: "20% off"}, {source: "partner-network", sourceId: "ad-3", kind: "advertisement", text: "Free delivery"}]

Constraints

  • Every supplied string is non-empty and has at most 200 characters.
  • At most 1,000 promotions are ingested into one feed.
  • Calls are sequential.

Notes

Inputs are valid. Duplicate identifiers, validation failures, and concurrent calls are outside the contract.

PRIVATE WORKSPACE

Checking your session…

The statement is public. The editor, editorial, submissions, and saved work are private.