Loyalty Points with Expiry

Hard ⏱ 18 min 26% acceptance ★★★★☆ 4.4
Points expire oldest-first. Write redeem(ledger, points) where ledger is a list of [earned_day, amount] batches sorted by day: consume points FIFO, mutating the ledger (drop exhausted batches, reduce partial ones) and returning True — or return False and leave the ledger untouched when the balance is short.

Examples

Example 1
Input
redeem([[1, 100], [5, 50]], 120)
Output
True, ledger becomes [[5, 30]]
Explanation

The day-1 batch is drained, 20 taken from day-5.

Constraints

  • All-or-nothing: insufficient balance changes nothing.
  • Consume oldest first.

Topics

Business LogicFIFO ledger

Companies

Starbucks TechFlipkartTata Neu

Hints

Hint 1

Check sum first for the atomicity guarantee.

Hint 2

Then walk from the front, slicing off consumed batches.

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