Parse an Amazon Search URL Query String Into Decoded Parameters

Last updated: November 29, 2026

Quick Overview

Given the query portion of a search URL such as `k=usb+c+cable&rh=n%3A172282&k2=&k=hub`, return a dictionary mapping each key to a list of its decoded values in order of appearance. Decode `+` as a space and `%XX` as the byte with that hex value.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

0

0 solved


Given the query portion of a search URL such as `k=usb+c+cable&rh=n%3A172282&k2=&k=hub`, return a dictionary mapping each key to a list of its decoded values in order of appearance. Decode `+` as a space and `%XX` as the byte with that hex value.

A warm-up in the style of Amazon's online assessment, framed around the search results page where filters and keywords arrive as URL parameters. The grader is checking careful tokenizing, correct handling of repeated and empty keys, and whether you hand-roll percent decoding correctly instead of guessing.

What the Interviewer Expects
  • Splits on & then on the first = only
  • Keeps repeated keys as an ordered list
  • Treats a key without = as an empty value
  • Decodes + and %XX, including multi-byte UTF-8 sequences
  • Linear time in the input length
Key Topics to Cover
string parsing
percent encoding
hash maps
UTF-8
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
  • How would you handle a malformed escape like %G1 or a trailing %?
  • How would you serialize the dictionary back into a canonical query string?
  • What changes if values may contain an encoded & (%26)?
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 is the raw query string, optionally starting with ?. Output maps decoded key to an ordered list of decoded values. Clarify: a bare key (a) means value "", empty segments from && are skip...

High-Level Design

Two passes over small pieces. First split the string on & and use partition('=') so a value can itself contain = (common in base64 tokens). Then decode the key and the value independently. Perce...


Submit Your Answer
Markdown supported