Rank Supported Locales From an Accept-Language Header With Quality Weights

Last updated: November 29, 2026

Quick Overview

Given an HTTP Accept-Language header and the list of locales a checkout page supports, return the supported locales in the order the browser prefers them. Handle exact tags, bare language tags like `en`, the `*` wildcard and `q` weights including `q=0` exclusions.

Stripe
Coding & Algorithms
Software Engineer
Stripe
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given an HTTP Accept-Language header and the list of locales a checkout page supports, return the supported locales in the order the browser prefers them. Handle exact tags, bare language tags like `en`, the `*` wildcard and `q` weights including `q=0` exclusions.

Stripe phone screens often use small, practical parsing tasks that grow in parts, and locale negotiation is real work for Stripe Checkout and hosted invoice pages that render in dozens of languages. The interviewer watches whether you write clean, readable code quickly and extend it without rewriting when each new rule is added.

What the Interviewer Expects
  • Split and trim entries defensively, tolerating extra spaces and empty segments
  • Keep a stable order: sort by q descending but preserve header order for equal weights
  • Match case-insensitively but return locales in the supported list's canonical casing
  • Never return a locale twice, even if several entries match it
  • Treat `q=0` as an explicit exclusion that also blocks wildcard matches
Key Topics to Cover
string parsing
stable sort
HTTP headers
localization
hash maps
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you fall back to a default locale when nothing matches?
  • What changes if supported locales include script subtags like `zh-Hant-TW`?
  • How would you test malformed headers such as `en;q=abc` or `;q=0.5`?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: a header string such as fr;q=0.5, en-US, *;q=0.1 and a list of supported locales like ["en-US", "fr-CA", "de-DE"]. Output: the supported locales ordered by preference. Rules, added in parts...

High-Level Design

Parse once into (-q, position, tag) tuples so a plain sort gives descending weight with ties kept in header order. Build a lowercase-to-canonical map of supported locales. Walk the sorted entries an...


Submit Your Answer
Markdown supported

Related Questions