URL Query String Parser

Difficulty: Easy · Topics: String Parsing, Map, URL

Difficulty: Easy  |  Tags: String Parsing, URL, Map

Description

Given a URL or query string, parse the query parameters into a Map> (since keys can repeat).

Implement:

parseQueryString(url) → Map<String, List<String>>

Examples

Example 1:

Input:  "https://example.com/api?name=Alice&age=30&city=NYC"
Output: {"name": ["Alice"], "age": ["30"], "city": ["NYC"]}

Example 2 — Repeated keys:

Input:  "?color=red&color=blue&size=large"
Output: {"color": ["red", "blue"], "size": ["large"]}

Example 3 — URL encoded:

Input:  "?msg=hello%20world&emoji=%F0%9F%98%80"
Output: {"msg": ["hello world"], "emoji": ["😀"]}

Example 4 — No query:

Input:  "https://example.com/page"
Output: {}

Constraints

Practice this problem

Related problems