Parse a Search URL Query String Into a Multi-Valued Parameter Map

Last updated: November 29, 2026

Quick Overview

Given a URL such as a Google Search results link, parse its query string into a map from parameter name to the list of its values in order, decoding percent escapes as UTF-8 bytes and plus signs as spaces, and tolerating flags without values and stray percent signs.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given a URL such as a Google Search results link, parse its query string into a map from parameter name to the list of its values in order, decoding percent escapes as UTF-8 bytes and plus signs as spaces, and tolerating flags without values and stray percent signs.

Search and Ads frontends at Google parse query strings constantly, and this is a realistic screen question about getting decoding exactly right. The interviewer probes repeated keys, byte-level UTF-8 decoding, fragments, and what happens with malformed escapes.

What the Interviewer Expects
  • Strips the fragment and isolates the query part after the first question mark
  • Keeps repeated keys as an ordered list of values
  • Decodes percent escapes into bytes and then UTF-8, not one character per escape
  • Treats plus as space in form encoding and keeps malformed escapes literally
  • Distinguishes a bare flag from an empty value only if asked, and says which it chose
Key Topics to Cover
String Parsing
Percent Encoding
UTF-8
Hash Map
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Write the inverse: serialize a parameter map back into a canonical, sorted query string.
  • Why can decoding before splitting on & and = cause bugs?
  • How would you defend against a query string with 100,000 parameters?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: a URL or a bare query, for example https://www.google.com/search?q=caf%C3%A9+near+me&tbm=isch&q=x&flag&e=#frag.
  • Output: `{"q": ["café near me", "x"], "tbm": ["isch"], "flag": [""], "e": [...
High-Level Design

Split first, decode second. Cut off the fragment at #, take everything after the first ?, split on &, and for each pair use partition("=") so values containing = survive. Only then percent-d...


Submit Your Answer
Markdown supported