FastPrepURL / Path Segment Compression Part 1
Problems/URL / Path Segment Compression Part 1

URL / Path Segment Compression Part 1

Stripe logoStripe● EasyFULLTIMENEW GRADPHONE SCREENONSITE INTERVIEW

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: July 26, 2026 — 🌺 I re-audited the original author-written source and rebuilt this practice version from the available interview report. It is about a 90% match to the available source. The slash-separated major parts, dot-separated minor parts, first/count/last compression rule, and worked URL examples come directly from the author-written onsite report. FastPrep supplies the standalone function signature, handling assumptions for very short or malformed segments, constraints, and additional examples.

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) → String

Examples

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 w compresses to w[0] + (len(w) - 2) + w[last], with the count written digit-by-digit.
  • No empty segments (no leading /, no consecutive ..).

Source note: The source image shows the shared two-part URL compression prompt and its two worked examples.

Interview reports that mention this question

  • Stripe New Grad Interview Question Bank: 47 Problems

Stripe interview experiences

  • Stripe SWE Onsite over Two Days: 1 Experience
  • Stripe New Grad SWE Phone Screen and Onsite: 2 Experiences
  • Stripe AI Coding Interview, Experienced SWE: 6 Experiences
  • Stripe SWE Intern Payout Scheduler Phone Screen: 1 Experience
  • Stripe New Grad SWE Onsite and HM Round: 1 Experience
All Stripe interview questionsSee Stripe hiring insights
Saved
class Solution {
    public String compress(String s) {
      // write your code here
    }
}
Checking account…