Parse Query String
Updated
Problem statement
You are given the query string of a GET request. Read its key-value pairs and return them as strings in one fixed format.
The input may start with ?. Parameters are separated by &. Each parameter has one of two forms:
key=valuestores the value forkey, read by its type (see below).!keystores the boolean valuetrueforkey. The!prefix must come at the start of the parameter. The forms!!keyand!key=valueare invalid.
A key may appear more than once. Keep all of its values, in the order they appear.
Value types
- Integer: a sequence of digits.
- Boolean:
trueorfalse. - Quoted string: drop the double quotes around it.
- List literal:
[item1,item2,...]turns into separate values, one per item, in order.
Practice rule: An empty list [] still creates the key, but it adds no values. If that key gets no other values, write it as key=.
Return one string per distinct key, in the order the keys first appear. Write key=value when the key has one value, and key=value1|value2|... when it has several.
Function
parseQueryString(query: String) → String[]Examples
Example 1
query = "?key1=1&key1=\"abc\"&key2=value1&!isBooleanField"return = ["key1=1|abc","key2=value1","isBooleanField=true"]key1 appears twice, so it keeps both values in order: the integer, then abc with its quotes removed. The shorthand !isBooleanField stores true. That gives one string for each of the three keys, in the order they first appear.
Example 2
query = "page=2&active=false&tags=[red,blue]&page=3"return = ["page=2|3","active=false","tags=red|blue"]page appears twice, with values 2 and 3, so its string joins them with |. active has the single value false. The list literal [red,blue] becomes two values for tags: red and blue. The keys come out in the order they first appear: page, active, tags.
Constraints
0 <= query.length <= 105- Keys are not empty. They contain only letters, digits, underscores or hyphens.
- Values never contain an unescaped
&. - The
!keyboolean shorthand only appears as a parameter on its own. Such a parameter has no=sign, and its key has exactly one!in front. - Items in a list literal are separated by commas with no whitespace. Items are plain strings, not quoted.
- The input is always well-formed. Invalid forms such as
!!key,!key=valueor nested list literals never appear.
More Airbnb Phone Screen questions
- Merge Event PreferencesPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Run-Length Encoding and DecodingPHONE SCREEN · Seen Nov 2026
- Read Across Sound TracksPHONE SCREEN · Seen Nov 2026
- Text JustificationPHONE SCREEN · Seen Nov 2026
- Decode and Store StringsPHONE SCREEN · Seen Oct 2026
- Print Sentences as TablePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Detonate Bombs with Chain ReactionsPHONE SCREEN · Seen Aug 2026
- Smallest Common RegionPHONE SCREEN · Seen Aug 2026
- Longest Chain BookingPHONE SCREEN · Seen Aug 2026
- Nested List Iterator with RemovePHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Most Frequent Call Path From Function Trace LogsRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
- Video Cache Hit Rates from a CSV LogTubi · PHONE SCREEN
- Resolve Variable Equations with Dependency ErrorsApplied Intuition · PHONE SCREENApplied Intuition interview questions
- Chatbot Away-Status RefactorOpenAI · PHONE SCREENOpenAI interview questions
- Chemical Formula WeightAgoda · PHONE SCREENAgoda interview questions
- Count Repeat Customers Across DatesAmazon · PHONE SCREEN
- Insert an Employee into an Organization HierarchyWaymo · PHONE SCREENWaymo interview questions
- JSON Identity VerificationKikoff · PHONE SCREENKikoff interview questions
Airbnb interview experiences
- Airbnb OA · November 2026
- Airbnb Campus and Full-Time SWE OA / Interviews: 9 Experiences
- Airbnb Intern Phone Interviews: 21 Experiences (Part 7 of 7)
- Airbnb Intern OA and Phone Screens: 17 Experiences (Part 6 of 7)
- Airbnb Intern OA and Onsite Rounds: 16 Experiences (Part 5 of 7)
- Airbnb Intern OA, Diplomacy Game: 19 Experiences (Part 4 of 7)