Code RoomAccept language parsing
MediumPrep Room Coding #202

Accept language parsing

CodingNetworking & APIsAlgorithms & data structuresMid–Senior~20 min

Parse an HTTP Accept-Language header and return the language tags in server preference order. The header is a comma-separated list of tags, each optionally carrying a quality weight ';q=VALUE' (a float in [0,1]); a tag with no q defaults to q=1.0. Sort by q descending; tags with equal q must retain their original left-to-right order (stable). Trim whitespace. An empty header returns an empty list.

Implement
parse_accept_language(header: str) → list[str]
Examples
in["en-US,en;q=0.9,fr;q=0.8"]out["en-US","en","fr"]
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
["en-US,en;q=0.9,fr;q=0.8"]["en-US","en","fr"]not run yetsample