Code Room
CodingMediumcod-g1151
Subject Networking protocolsLevel Mid–Senior~22 minCommon in Networking & APIs · Algorithms & data structures interviewsIndustries Software development, Technology

Question

Parse an HTTP Range request header for a resource of known total_size bytes. The header has the form 'bytes=START-END', where either side may be omitted: 'bytes=0-499' is the first 500 bytes, 'bytes=500-' is from 500 to the end, and 'bytes=-500' is the last 500 bytes. If only the first byte-range-spec is needed, ignore anything after a comma. Clamp END to total_size-1. Return [start, end] as resolved inclusive offsets, or [-1, -1] if the unit is not 'bytes', the range is unsatisfiable (start beyond the resource), or a suffix length of 0.

Implement
parse_range(header: str, total_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.