Problem Β· String
URL Segment Compression Part 2 β Bounded Minor Parts
Learn this problemProblem 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.
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