Parse and Expand Supported Card Identifiers
Reported by candidates from Stripe's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Input size is the first thing to check on this Stripe OA, reported January 2025. Supported is capped at 1000 and each entry is at most 99 characters, so a nested prefix scan per entry is fine. That means the work is in the rules, not in speed. It's a string parsing problem with a deferral twist. Read two digits, slice that many characters, repeat until the lone 0. Then expand generic prefixes without double-emitting. If you blank on the ordering logic mid-assessment, StealthCoder runs invisibly as a safety net while you're live. Know the shape first.
The problem
An encoded string contains an ordered sequence of card identifiers. Every entry begins with a two-digit decimal length followed by exactly that many identifier characters. A final single 0 terminates the string. Return the unique supported card identifiers represented by the sequence, preserving the encoded entry order: If an entry exactly equals a supported identifier, return that identifier at this position. Otherwise the entry is a generic prefix. Expand it to supported identifiers with that prefix, using supported order. If a matching supported identifier appears as an exact entry later in the encoded sequence, defer it to that later position instead of emitting it for the earlier generic prefix. Never return the same supported identifier twice. Earlier stages and a related variant These exercises are ungraded follow-ups. The judged function remains resolveSupportedCards. parseCardIdentifiers(String encoded) -> String[]: decode every entry in order. Preserve repeated entries. The final single 0 is a terminator, so "0" decodes to an empty array. For example, "02AA02AA01B0" returns ["AA","AA","B"]. exactSupportedCards(String encoded, String[] supported) -> String[]: return only decoded entries that exactly belong to supported. Preserve their encoded order and repeated occurrences. For the preceding stream and ["AA"], return ["AA","AA"]. This stage performs no generic-prefix expansion. supportedCardsWithRids(String encoded, String[] supported, String[] supportedRids) -> String[]: decode the stream, then retain each decoded identifier if it is an exact supported identifier or starts with a supplied RID. This is a separate three-input stream-filtering variant; it does not expand a generic entry into identifiers from supported, defer later entries, or remove duplicate occurrences. For "04AA0104BB0204AA0104CC030", supported ["BB02"] and RIDs ["AA"], return ["AA01","BB02","AA01"]. For these follow-ups, assume the same valid two-digit encoding and ASCII identifier alphabet. Support and RID arrays may be empty; their entries are non-empty ASCII identifiers. Use the RID as a prefix, and use the exact-or-prefix rule stated above. The related report did not specify output order or duplicate handling, so retaining stream order and duplicate occurrences is this variant's deterministic practice convention. The ordered report confirms deferring a later exact identifier after an earlier generic entry. It leaves repeated broader-prefix demotion unconfirmed. This main exercise keeps the first emission of an identifier and applies only the stated later-exact deferral. Another report says demotion was unnecessary in its interview; that variant does not replace the main exercise's explicit rule. Function resolveSupportedCards(encoded: String, supported: String[]) → String[] Examples Example 1 encoded = "04432108432100020" supported = ["43210001","43210002","43210003"] return = ["43210001","43210003","43210002"] The generic prefix 4321 expands in supported order, but 43210002 is deferred because it appears as the next exact entry. Example 2 encoded = "18DS012345678987654310AI012345670" supported = ["AI01234567","DS0123456789876543"] return = ["DS0123456789876543","AI01234567"] Both entries are exact supported identifiers, so their encoded order is retained. Constraints 1 <= supported.length <= 1000; supported identifiers are unique. Each encoded entry length is between 1 and 99. The encoded string is valid and ends with one terminal 0. Generic entries match at least one supported identifier. Identifiers contain ASCII letters and digits only.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Two passes. Pass one: parse the string into a list of entries using an index pointer. Read the two-digit length, slice, advance. Stop at the terminal 0. Build a set of supported identifiers and a map from each exact entry to its last position in the list. Pass two: walk entries in order. If an entry is exactly in supported, emit it if unseen. Otherwise it's a prefix. Loop through supported in its given order, and for each one that starts with the prefix, skip it if it appears as an exact entry at a later index, and skip it if already emitted. Otherwise emit it. The classic pitfall is the terminator. A length of 00 would look like zero, but the final single 0 is one character, so check for it before reading two digits. Another trap is emitting an exact match early, then again later. Keep one emitted set. Brute force is fine at these limits. StealthCoder is your hedge if the deferral rule tangles on the live OA.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Parse and Expand Supported Card Identifiers 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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Stripe's OA.
Stripe reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Parse and Expand Supported Card Identifiers FAQ
How hard is this Stripe OA question really?+
Medium on paper, but the difficulty is reading the rules carefully. The parsing is simple pointer work. The deferral rule and the no-duplicates rule are where candidates lose points, so trace both examples by hand before you code.
What's the trick to the deferral rule?+
Precompute, for each supported identifier, the last index where it appears as an exact entry. When expanding a generic prefix at index i, skip any matching identifier whose exact entry index is greater than i. It gets emitted later at its own position.
How do I parse the encoded string without bugs?+
Use an index. If the current character is 0 and it's the final character, stop. Otherwise read two digits as the length, slice that many characters, and move the pointer forward by length plus two. Check the terminator before reading digits.
Do I need a trie or something fancy for prefix matching?+
No. Supported has at most 1000 items and entries are short, so calling startsWith across the supported list for each generic entry is fine. A trie adds code and bug risk without any real gain here.
How do I prepare for this in 48 hours?+
Write the parser and test it on the 0 case and the repeated AA example. Then code the expansion with a seen set and the later-exact map. Run both given examples. Don't spend time on the ungraded follow-up stages unless you finish early.