← Questions
Decode and expand supported card identifiers
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 Jan 2025. It tests strings, parsing and hash map.
A payment card reports the applications it supports as one encoded string: each entry is a two-digit length followed by that many characters, and a single 0 ends the string. A terminal has its own ordered list of supported identifiers.
- Decode the string into its entries, in order.
- Keep only the entries that exactly match an identifier the terminal supports.
- Treat an entry that is not an exact match as a prefix and expand it to every supported identifier that starts with it, in the terminal's order. Never output an identifier twice, and if an identifier appears later as an exact entry, place it there instead of under the earlier prefix.
Clarifying questions
- Is the length always two decimal digits? How should a malformed string be handled (a length past the end, no closing
0)? - Are identifiers compared case-sensitively?
- If the same exact entry appears twice, is it output once?
- If a prefix matches nothing the terminal supports, is it dropped?
What a strong answer covers
- A decoder with a cursor: read two digits, read that many characters, repeat until the lone
0; malformed input raises an error naming the position. - Part 2 with a set of supported identifiers for O(1) checks.
- Part 3 in two passes: first note which identifiers appear later as exact entries, then walk the entries in order, emitting exact matches in place and expanding each prefix to the supported identifiers that start with it, in the terminal's order, skipping any already emitted or still to come as an exact entry.
- Cost O(entries × supported) for prefix matching, or a trie over the supported identifiers when lists are long.
- Tests: a string that is only the terminator, a prefix that is also an exact identifier, overlapping prefixes, and an identifier reached by two prefixes.
Follow-ups
- The terminal gives each identifier a priority; order the output by it.
- Entries nested inside entries, as in a tag-length-value encoding.
- Strict validation that reports the first error and its position.
Where it's asked
- Stripe · Technical phone screen · Last asked Jan 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
