Parse and Expand Supported Card Identifiers
Problem statement
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
supportedorder. - 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 single0is 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 tosupported. 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 fromsupported, 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
1and99. - 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.