URL Segment Compression Part 2 — Bounded Minor Parts
Updated
Problem statement
A path is split into major parts by /. Each major part is split into minor parts by .. Base-compress a word w as its first character, the number of omitted middle characters, and its last character.
For each major part independently:
- If it has at most
mminor parts, base-compress every minor part exactly as in Part 1. - If it has more than
mminor parts, base-compress the firstm-1parts separately. Concatenate the original characters of all remaining minor parts (drop their dots) and base-compress that concatenated word as the final token.
The merge uses original characters, never already-compressed tokens. Rejoin minor tokens with . and major parts with /.
Practice sequence
- Part 1: compress every minor part
- Part 2: cap each major at m minor tokens (current)
Function
compressBounded(s: String, m: int) → StringExamples
Example 1
s = "stripe.com/payments/checkout/customer.john.doe"m = 2return = "s4e.c1m/p6s/c6t/c6r.j5e"customer is compressed separately; john and doe are concatenated to johndoe and compressed as j5e. One-minor majors such as payments still become p6s.
Example 2
s = "www.api.stripe.com/checkout"m = 3return = "w1w.a1i.s7m/c6t"The first two minor parts stay separately compressed. stripe and com are merged from original text to stripecom, producing s7m. checkout remains c6t.
Constraints
m >= 1.- The input has no empty major or minor parts.
- Every minor part has length at least 2.
- The middle count may contain multiple digits.
- A one-minor major is base-compressed just as in Part 1.
Source note: The source image shows the shared two-part URL compression prompt and its two worked examples.
More Stripe Onsite Interview questions
- Render a Task Tree from CSV RowsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Invoice / Payment ReconciliationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Parse Boolean Rule ExpressionsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Transaction Rule Expression EvaluatorONSITE INTERVIEW · Seen Oct 2026
- Evaluate Ordered Action RulesPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- WebSocket Load Balancer — Parts 1–5OA · ONSITE INTERVIEW · Seen Sep 2026
- Rule-Driven Transaction Fraud DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Account Balance Manager Part 3 - Platform CoverageONSITE INTERVIEW · Seen May 2026
- Account Balance Manager Part 2 - Reject OverdraftsONSITE INTERVIEW · Seen May 2026
- Account Balance Manager Part 1 - Calculate TotalsONSITE INTERVIEW · Seen May 2026
Similar questions at other companies
- Evaluate an Arithmetic Expression Written in WordsBrex · PHONE SCREEN
- Single-Pass S-Expression ParserBaseten · ONSITE INTERVIEWBaseten interview questions
- Top K Movies by Play Count from CSV DataTubi · PHONE SCREEN
- Remove Parentheses from a Plus-Minus ExpressionOracle · PHONE SCREENOracle interview questions
- Parse Nested Message TypesApplied Intuition · PHONE SCREENApplied Intuition interview questions
- Most Frequent Call Path From Function Trace LogsRoblox · PHONE SCREENRoblox interview questions
- Decode StringCompass International Holdings · PHONE SCREENCompass International Holdings interview questions
- Flatten a Mixed JSON ListNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
- Valid Number with ExponentsLinkedIn · PHONE SCREENLinkedIn interview questions
- Transform Dotted Keys into a Nested MapProofpoint · ONSITE INTERVIEW