URL Query-String Parser

Asked at AirbnbPhone screen

Reported by the problem's creator, not verified

You are parsing the query string of a URL into a map. The query string is everything after the first ?. It is a list of parameters separated by &, and each parameter is either key=value or just key.

Write parse_query(url).

Examples

  1. Example 1

    Input: url = ?a=b&c=d

    Output: {"a":"b","c":"d"}

    Explanation: Both keys appear once, so each maps to a plain string.

  2. Example 2

    Input: url = ?sd&a=b&a=c&a=d&sd

    Output: {"sd":[true,true],"a":["b","c","d"]}

    Explanation: sd has no =, so its value is true. a appears three times, so its values are collected in order: ["b", "c", "d"]. sd appears twice with no value each time, giving [true, true].

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.