Problem Β· String
HTTP Accept-Language Matching (Exact, Prefix, Wildcard)
Learn this problemProblem 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 problems
- Group Linked Merchant RecordsPHONE SCREEN Β· Seen Jul 2026
- Invoice / Payment ReconciliationPHONE SCREEN Β· Seen Jul 2026
- Incident MonitorOA Β· Seen Jul 2026
- Merchant Fraud Risk ScoringOA Β· Seen Jul 2026
- WebSocket Load Balancer β Basic Load Balancing (Part 1)OA Β· Seen Jul 2026
- Rule-Driven Transaction Fraud DetectionOA Β· PHONE SCREEN Β· Seen Jul 2026
- Deployment Window SchedulerOA Β· Seen Jul 2026
- Directly Linked UsersOA Β· Seen Jun 2026