Coupon Redemption Tally with Cap Check

Hard ⏱ 18 min 27% acceptance ★★★★★ 4.5
Write a function over_redeemed(redemptions, caps) where redemptions is a list of coupon code strings (one entry per redemption) and caps is a dict mapping coupon code to its maximum allowed redemptions. Return a sorted list of coupon codes whose actual redemption count in redemptions exceeds its cap in caps. Codes not present in caps are unlimited and never flagged.

Examples

Example 1
Input
over_redeemed(['SAVE10', 'SAVE10', 'SAVE10', 'FLAT50', 'FLAT50'], {'SAVE10': 2, 'FLAT50': 5})
Output
['SAVE10']
Explanation

SAVE10 used 3 times but capped at 2; FLAT50 used 2 times, within its cap of 5.

Constraints

  • Only codes present in caps can be flagged.
  • Result must be sorted alphabetically.

Topics

Dictionariesbusiness logicCounter

Companies

RazorpayPayPal

Hints

Hint 1

Use `collections.Counter(redemptions)` to get actual counts.

Hint 2

For each code in caps, compare its Counter count to its cap.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.