Indexed API Field Pattern Queries
Reported by candidates from Stripe's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Stripe reported this one in July 2025, and the title gives away the setup: index API fields, then answer pattern queries fast. If you've got an OA invite, the question is what to build. You parse every record once into a map from key to a collection of values, then each query only touches its own key's values. Exact match is a set lookup. Prefix match needs something smarter than a scan. A trie per key or a sorted list with binary search both work. StealthCoder is the safety net if you blank during the live OA, but the design is simple once you see it.
The problem
You receive encoded API records in records and must answer the field-pattern checks in queries. Preprocess the records once, then return one boolean for each query in input order. Record encoding Each record contains one or more semicolon-separated key=value fields. Keys are unique within a record. A field value is considered received under its key even if the same pair appears in several records. Query encoding Each query also has the form key=pattern: If pattern has no *, it matches only the exact value. If pattern ends in *, it matches every value that starts with the prefix before *. The pattern * matches any value stored under that key. A query is true when at least one parsed record contains the requested key with a matching value. A missing key or a pattern with no matching value is false. Comparisons are case-sensitive. Build an index over the parsed fields so that each query examines only the values stored under its requested key instead of rescanning all records. Function matchApiFieldPatterns(records: String[], queries: String[]) → boolean[] Examples Example 1 records = ["method=get;path=users","method=post;path=payments","method=get;path=user_settings"] queries = ["method=get","path=pay*","path=user*","method=put","path=*"] return = [true,true,true,false,true] The exact query method=get succeeds. The path prefixes pay and user match received values, while no record contains method=put. The bare wildcard matches any stored path. Example 2 records = ["event=charge;id=abc123","event=chargeback;id=abd900","event=refund;id=abc"] queries = ["event=charge","event=charge*","id=abc","id=abc*","id=ab*","missing=*"] return = [true,true,true,true,true,false] An exact pattern distinguishes charge from chargeback, while charge* accepts both. The exact value abc exists, and both prefix checks have matching identifiers. No parsed record contains the key missing. Example 3 records = ["type=ping;region=us_east","region=eu;type=pong","type=ping;region=us_west"] queries = ["region=us_*","type=pong","region=e","type=*"] return = [true,true,false,true] Field order inside a record does not matter. The prefix us_ matches two regions, the exact value pong exists, and exact e does not equal eu. At least one value exists for type=*. Constraints 0 <= records.length <= 50000. 0 <= queries.length <= 50000. Each record contains from 1 through 20 unique fields. Every key and value is nonempty and contains only lowercase ASCII letters, digits, and underscores. Each query contains one existing or absent key, one =, and a nonempty pattern. The only allowed wildcard is one optional final *. The total number of characters across records and queries is at most 500000. All record and query strings follow the stated encodings.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The data structure is a hash map from key to a per-key value index. For exact queries, a hash set per key answers in O(1). For prefix queries like path=pay*, you have two clean options. Build a trie per key and walk the prefix, or keep a sorted array of distinct values per key and binary search for the first value >= prefix, then check it starts with the prefix. The bare * just checks the key exists. The common pitfall is rescanning all values per query, which the problem explicitly forbids and which blows up at 50000 by 50000. Another trap is treating e as a prefix when it's exact, so check whether the pattern ends in * before anything else. Split on the first = only after parsing, and dedupe values. If your mind goes blank on the trie or the binary search bound, StealthCoder can feed you a working version during the live OA.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Indexed API Field Pattern Queries cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Stripe's OA.
Stripe reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Indexed API Field Pattern Queries FAQ
What's the trick in Stripe's Indexed API Field Pattern Queries?+
Preprocess once into a map from key to an index of values. Exact patterns hit a hash set. Prefix patterns hit a trie or a sorted list with binary search. Never scan all records per query, since the input sizes make that too slow.
Trie or sorted list with binary search for the prefix queries?+
Either passes. A sorted list per key is shorter to write: find the lower bound of the prefix and check that value startsWith the prefix. A trie is more code but conceptually direct. Pick whichever you can write without bugs under pressure.
How hard is this problem really?+
Medium-ish. The algorithm is light, but the parsing and the three query cases (exact, prefix, bare star) create small bugs. Most of the work is clean implementation, not clever insight.
What edge cases should I test before submitting?+
Test a missing key, a bare * on an existing key, an exact pattern that is only a prefix of a stored value (like e versus eu), and duplicate pairs across records. Also try empty records or empty queries, since both can be length zero.
How do I prepare in 48 hours?+
Write the parser and the key-to-set-and-sorted-list index from scratch twice. Practice the binary search lower bound with a startsWith check. Then run the three examples from the problem by hand. That covers nearly everything this question tests.