Code RoomParse query string
MediumPrep Room Coding #1443

Parse query string

CodingAlgorithms & data structuresMid–Senior~25 min

Parse a URL query string into a dict. Strip a leading `?` if present. Split on `&` into pairs; each pair is `key=value` (split on the first `=` only) or a bare `key` with no `=` (value is the empty string). Percent-decode both keys and values (e.g. `%20` -> space). If the same key appears more than once, its value becomes a list of all occurrences in order; a single occurrence stays a plain string. Empty pairs (from `&&`) are skipped. An empty input yields an empty dict.

Implement
parse_query(qs: str) → dict
Examples
in["a=1&b=2"]out{"a":"1","b":"2"}
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 25 min
InputExpectedGot
["a=1&b=2"]{"a":"1","b":"2"}not run yetsample