Ledger window volume
A billing service keeps an append only ledger, so stamps holds the Unix second of each entry in nondecreasing order, and two entries can share a second. A support tool needs the volume inside a window before it renders anything. Given stamps, start_stamp and end_stamp, return how many entries fall in the half open window: an entry counts when its stamp is at or after start_stamp and strictly before end_stamp. An entry written exactly at start_stamp counts, one written exactly at end_stamp does not, and that convention is what lets neighbouring windows tile without double counting a single entry. Return 0 when the window is inverted or empty, meaning end_stamp is at or before start_stamp, and 0 for an empty ledger. The ledger holds years of history, so counting entries one at a time is too slow.
count_ledger_entries(stamps: list[int], start_stamp: int, end_stamp: int) → int[[100,200,200,300,400],200,400]out3[[100,200,300],300,300]out0[[100,200,300],0,1000]out3State 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.
[[100,200,200,300,400],200,400]3not run yetsample[[100,200,300],300,300]0not run yetsample[[100,200,300],0,1000]3not run yetsample