Code RoomHTTP range header
MediumPrep Room Coding #196

HTTP range header

CodingNetworking & APIsAlgorithms & data structuresMid–Senior~20 min

Parse an HTTP Range header against a known resource size. The header looks like 'bytes=START-END'. Support three forms: 'bytes=N-M' (explicit range), 'bytes=N-' (from N to end), and 'bytes=-N' (the last N bytes, a suffix range). Return [start, end] as inclusive 0-based byte offsets, clamping END to size-1. If the header is unsatisfiable (start beyond the resource, malformed, wrong unit, or a zero-length suffix), return [-1, -1].

Implement
parse_range(header: str, size: int) → list[int]
Examples
in["bytes=0-499",1000]out[0,499]
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 20 min
InputExpectedGot
["bytes=0-499",1000][0,499]not run yetsample