Code RoomLedger window volume
EasyPrep Room Coding #4733

Ledger window volume

CodingAlgorithms & data structuresEntry–Mid~16 min

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.

Implement
count_ledger_entries(stamps: list[int], start_stamp: int, end_stamp: int) → int
Examples
in[[100,200,200,300,400],200,400]out3
in[[100,200,300],300,300]out0
in[[100,200,300],0,1000]out3
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 16 min
InputExpectedGot
[[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