Decompose an HTTP URL into Components
Updated
Problem statement
Parse one valid HTTP or HTTPS URL and return these six components in order:
- scheme, without
://; - host;
- explicit port, or an empty string when no port is written;
- path;
- query, without
?; - fragment, without
#.
URL subset for this exercise
- The scheme is exactly
httporhttps. - The host is nonempty and contains lowercase English letters, digits, dots, or hyphens.
- An optional port follows the host as
:digits. - An optional path begins with
/. If it is absent, return/. - An optional query begins with
?, and an optional fragment begins with#. - The query and fragment may be empty. Delimiter characters do not appear inside their component values.
Function
decomposeHttpUrl(url: String) → String[]Examples
Example 1
url = "https://api.example.com:8443/v1/payments?limit=10#recent"return = ["https","api.example.com","8443","/v1/payments","limit=10","recent"]Every optional component is present. The returned query and fragment omit their leading delimiters.
Example 2
url = "http://example.com?debug=#"return = ["http","example.com","","/","debug=",""]No explicit port or path is written. The query is debug=, and the fragment is present but empty.
Constraints
8 <= url.length <= 2 * 10^5.urlfollows the URL subset stated above.- The explicit port, when present, contains one to five decimal digits.
- For this exercise, preserve component text exactly as written.
More Stripe Phone Screen questions
- Invoice / Payment ReconciliationPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesPHONE SCREEN · Seen Dec 2026
- Split Tender Part 4 - RefundsOA · PHONE SCREEN · Seen Nov 2026
- Merchant Payout Reserve CalculatorPHONE SCREEN · Seen Nov 2026
- Parse Boolean Rule ExpressionsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Linked Merchants Within Two HopsPHONE SCREEN · Seen Nov 2026
- Merchant Matching, Parts 1–2: Shared Fields and Weighted ThresholdsPHONE SCREEN · Seen Nov 2026
- Business Account KYC Verification — Parts 1–5PHONE SCREEN · Seen Nov 2026
- Financial Account LedgerOA · PHONE SCREEN · Seen Nov 2026
- Merchant Payout Scheduler, Part 2: Per-Merchant SchedulesPHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Search and Format ContactsAdyen · PHONE SCREENAdyen interview questions
- Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
- Format a Signed Integer with CommasHudson River Trading · PHONE SCREENHudson River Trading interview questions
- Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions
- Run-Length DecodingApple · PHONE SCREENApple interview questions
- Trace Pointer Rebinding and Pointee UpdatesArista Networks · PHONE SCREENArista Networks interview questions
- Match a Variadic Function SignatureConfluent · PHONE SCREENConfluent interview questions
- Decode and Store StringsAirbnb · PHONE SCREENAirbnb interview questions
- Delimiter-Parsing String Iteratoramo · PHONE SCREEN
- SimpleRDD Word CountDatologyAI · PHONE SCREEN