Problem Β· String
URL / Path Segment Compression Part 1
Learn this problemProblem statement
You are given a string built from major parts separated by /, where each major part is built from minor parts separated by . β for example abcd/erfgsh/google.com.abc.
Compress every minor part with this rule: keep its first and last character and replace the middle with the count of removed characters. Formally a minor part w becomes w[0] + (len(w) - 2) + w[last]. Then rejoin minor parts with . and major parts with /.
For example abcd becomes a2d (drop bc, count 2), and google becomes g4e. Append the count digit-by-digit, so a long segment like googlecomabc (length 12) becomes g10c β the middle count can be multiple digits.
Assume every minor part has length >= 2, and that there are no empty segments (no leading / and no consecutive ..).
Function
compress(s: String) β StringExamples
Example 1
s = "abcd/erfgsh/google.com.abc"return = "a2d/e4h/g4e.c1m.a1c"abcd -> a2d (drop bc). erfgsh -> e4h (drop rfgs, count 4). google -> g4e, com -> c1m, abc -> a1c; the third major rejoins its minors with dots: g4e.c1m.a1c.
Example 2
s = "googlecomabc"return = "g10c"A single segment of length 12 keeps the first char g and last char c, with the middle count 10 appended digit-by-digit, giving g10c. The multi-digit count is the common trap.
Constraints
- Major parts are separated by
/; within a major, minor parts are separated by.. - Every minor part has length
>= 2. - A minor part
wcompresses tow[0]+(len(w) - 2)+w[last], with the count written digit-by-digit. - No empty segments (no leading
/, no consecutive..).
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