Code RoomBid lifetime max tracking
MediumPrep Room Coding #4871

Bid lifetime max tracking

CodingDistributed systemsAlgorithms & data structuresMid–Senior~22 min

An ad exchange records one bid per second for a single slot. The bid that lands in second i is worth amounts[i] cents and stays live for lifetimes[i] seconds, so it can be accepted during seconds i through i + lifetimes[i] - 1. A lifetime of 0 means the bidder pulled it the instant it landed, so it is never live. At the end of every second the exchange publishes the largest amount among the bids still live in that second, or -1 when nothing is live. Return one published number per second, in order. Amounts and lifetimes are never negative, and the two lists have the same length.

Implement
live_bid_peaks(amounts: list[int], lifetimes: list[int]) → list[int]
Examples
in[[50,90,40],[3,1,2]]out[50,90,50]
in[[70,20],[1,1]]out[70,20]
in[[80,30,30,10],[1,4,1,1]]out[80,30,30,30]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 22 min
InputExpectedGot
[[50,90,40],[3,1,2]][50,90,50]not run yetsample
[[70,20],[1,1]][70,20]not run yetsample
[[80,30,30,10],[1,4,1,1]][80,30,30,30]not run yetsample