← Questions
Merge prioritized configuration tables
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 onsite coding (debug, integrate, build) round, last asked Apr 2026. It tests parsing, hash map and validation.
You get several configuration tables, each with an integer priority. Every table is a list of strings meant to look like key=value. Merge the tables so that each key takes its value from the highest-priority table that sets it, then return the requested keys.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
merge_configs(tables: list[list[str]], priorities: list[int], selected_keys: list[str]) -> list[str]- A valid key matches
[A-Za-z_][A-Za-z0-9_]*. - A valid value is
0, or an optional-followed by a non-zero digit and more digits, and it fits in a signed 32-bit integer. A leading zero, a+, an empty value or an extra=make the entry invalid. - Invalid entries are ignored; the rest of their table still counts.
- The table with the higher priority wins a key. With equal priorities, the table that appears later wins.
- Return
key=valuefor each selected key that has a merged value, in the order ofselected_keys.
- A valid key matches
Example
merge_configs([["a=1", "b=2"], ["b=3", "c=4"]], [1, 2], ["b", "c"])
-> ["b=3", "c=4"]
merge_configs([["rate=10", "timeout=bad"], ["rate=7", "timeout=30"], ["rate=2147483648", "extra=4"]],
[5, 2, 10], ["rate", "timeout", "extra"])
-> ["rate=10", "timeout=30", "extra=4"] # "bad" and the overflowing rate are skipped
merge_configs([["a=1", "b=2"], ["a=8"], ["b=9"]], [3, 3, 2], ["a", "b", "missing"])
-> ["a=8", "b=2"] # later equal-priority table wins a
Constraints
- Up to 100,000 tables and 200,000 entries in total; each entry is 1 to 100 characters.
- A table sets any valid key at most once. Priorities are signed 32-bit integers.
- Process the tables in one pass. Do not sort all entries by priority.
Clarifying questions
- Is
-0a valid value? (No: only0is.) - Is whitespace around
=allowed? - Does an invalid entry with a high priority hide a valid one with a lower priority? (No: invalid entries are ignored.)
- What if
selected_keysrepeats a key?
What a strong answer covers
- A strict validator for keys and values, including the 32-bit range check on the digit string.
- One pass that keeps, per key, the best
(priority, table index)seen so far and its value; a later table replaces it when its priority is>=. - O(total entries + selected keys) time.
- Tests for every invalid form, equal priorities, overflow at exactly
2147483647and2147483648, and-2147483648.
Follow-ups
- Values can be strings and booleans as well. How does validation change?
- Report, for each key, which table its value came from.
- Tables update one at a time. Keep the merged view current without re-merging.
Where it's asked
- Stripe · Onsite coding: debug, integrate, build · Last asked Apr 202660 min · Project editor with starter code and tests: fix bugs in an unfamiliar codebase, wire an external API spec into a service, or complete a skeleton in parts · Varies by session: some onsites have one AI-assisted session and an integration session without AI
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
