Code Room
CodingMediumcod-g1035
Subject Protocol http rangeLevel Mid–Senior~20 minCommon in Networking & APIs · Algorithms & data structures interviewsIndustries Software development, Technology

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.