← Questions
Field pattern queries over key-value API records
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Stripe's technical phone screen, last asked Jul 2025. It tests trie, hash map and strings.
API records are strings of key=value fields separated by semicolons, such as method=get;path=users. Preprocess the records once, then answer many queries of the form key=pattern. A query is true when at least one record has that key with a value that matches the pattern.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
answer(records: list[str], queries: list[str]) -> list[bool]— one result per query, in order. Patterns:- no
*: the value must equal the pattern exactly; - ends with
*: the value must start with the text before the*; -
*alone: any value under that key.
- no
- A missing key gives
False. Comparisons are case-sensitive.
Example
records = ["method=get;path=users", "method=post;path=payments", "method=get;path=user_settings"]
queries = ["method=get", "path=pay*", "path=user*", "method=put", "path=*"]
-> [True, True, True, False, True]
records = ["event=charge;id=abc123", "event=chargeback;id=abd900", "event=refund;id=abc"]
queries = ["event=charge", "event=charge*", "id=abc", "id=ab*", "missing=*"]
-> [True, True, True, True, False] # exact "charge" does not match "chargeback"
Constraints
- Up to 50,000 records and 50,000 queries; at most 500,000 characters in total.
- Each record has 1 to 20 fields with unique keys. Keys and values use lowercase letters, digits and
_. - The only wildcard is one optional
*at the end.
Clarifying questions
- Can a value contain
=or;? - Can the wildcard appear anywhere other than the end?
- Should the answer be a boolean, or the matching records?
- Do records arrive once up front, or keep arriving between queries?
What a strong answer covers
- An index from key to the set of values seen under it, built in one parse.
- Exact queries as a set lookup in O(1).
- Prefix queries without scanning every value: either a sorted list per key with binary search for the first value
>= prefix(then check it starts with the prefix), or a trie per key. - The trade-off: sorted lists are compact and simple; a trie answers in O(prefix length) but uses more memory and supports incremental inserts more naturally.
- Total cost: O(total characters) to build plus O(log V + prefix length) per prefix query.
- Tests: exact vs prefix (
chargevscharge*),*alone, a missing key, field order inside a record.
Follow-ups
- Return the number of records that match, not just whether any does.
- Support
*in the middle of a pattern (pa*ts). - Records keep arriving between queries. Which index handles inserts better?
- Combine several conditions with AND across fields of the same record.
Where it's asked
- Stripe · Technical phone screen · Last asked Jul 202560 min · One realistic task in parts, in a project editor (CoderPad project mode or HackerRank Projects) with several files and tests
What it tests
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
