HTTP Accept-Language Matching (Exact, Prefix, Wildcard)
Updated
Problem statement
Practice sequence: Exact, prefix, and wildcard matching → Quality scores (q-factors).
You serve localized content by resolving a browser's HTTP Accept-Language header against the languages your server supports. The header lists language tags in order of preference, separated by commas, with optional surrounding spaces.
Given acceptHeader and supportedLanguages, return the supported tags that work for the request in descending client preference order. Apply these source-defined parts as you scan the header left to right:
- Part 1 — exact match: a tag such as
en-USmatches the same supported tag. - Part 2 — generic language: a region-less tag such as
enmatches supported variants that start withen-. - Part 3 — wildcard:
*matches every supported tag not already selected.
When one header entry matches several supported languages, keep their order from supportedLanguages. Never return a supported tag more than once.
Function
parseAcceptLanguage(acceptHeader: String, supportedLanguages: String[]) → String[]Examples
Example 1
acceptHeader = "fr-FR, fr"supportedLanguages = ["en-US", "fr-CA", "fr-FR"]return = ["fr-FR", "fr-CA"]fr-FR is an exact match and comes first. Then the generic fr matches the remaining French variant fr-CA (fr-FR is skipped because it is already used). en-US is never requested.
Example 2
acceptHeader = "fr-FR, fr, *"supportedLanguages = ["en-US", "fr-CA", "fr-FR"]return = ["fr-FR", "fr-CA", "en-US"]fr-FR matches exactly. fr matches fr-CA. The wildcard * then grabs the last unmatched supported tag, en-US.
Example 3
acceptHeader = "en-US, fr-CA, fr-FR"supportedLanguages = ["fr-FR", "en-US"]return = ["en-US", "fr-FR"]en-US is first in the header and supported. fr-CA is not supported. fr-FR is third in the header and supported. Order follows the header preference.
Constraints
acceptHeaderis a comma-separated list of tags with optional surrounding spaces.- Exact matches use the full tag; a region-less generic tag matches every supported tag starting with
generic-. *matches all not-yet-matched supported tags, insupportedLanguagesorder.- Preserve the header's preference order; never output a supported tag twice.
- Return the matched supported tags as a
String[].
More Stripe Phone Screen questions
- Merchant Payout Scheduler, Part 2: Per-Merchant SchedulesPHONE SCREEN · Seen Nov 2026
- Financial Account LedgerOA · PHONE SCREEN · Seen Nov 2026
- Business Account KYC Verification — Parts 1–5PHONE SCREEN · Seen Nov 2026
- Render a Task Tree from CSV RowsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Invoice / Payment ReconciliationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Linked Merchants Within Two HopsPHONE SCREEN · Seen Nov 2026
- Portfolio Valuation, Part 1PHONE SCREEN · Seen Nov 2026
- Account Roles With Parent-User InheritancePHONE SCREEN · Seen Nov 2026
- Merchant Payout Scheduler, Part 3: Hold PeriodsPHONE SCREEN · Seen Nov 2026
- Merchant Payout Scheduler, Part 1PHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Count Repeat Customers Across DatesAmazon · PHONE SCREEN
- Insert an Employee into an Organization HierarchyWaymo · PHONE SCREENWaymo interview questions
- Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
- Deep Merge with a Conflict ResolverAutodesk · ONSITE INTERVIEWAutodesk interview questions
- Group AnagramsWorkday · PHONE SCREEN
- Video Cache Hit Rates from a CSV LogTubi · PHONE SCREEN
- Apply Operations to Make a String EmptyFlexport · PHONE SCREENFlexport interview questions
- Resolve Variable Equations with Dependency ErrorsApplied Intuition · PHONE SCREENApplied Intuition interview questions
- Most Frequent Call Path From Function Trace LogsRoblox · PHONE SCREENRoblox interview questions