FastPrepURL Segment Compression Part 3 — Global Token Budget
Problems/URL Segment Compression Part 3 — Global Token Budget

URL Segment Compression Part 3 — Global Token Budget

Stripe logoStripe● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Stripe new-grad onsite interview. The source clearly reports a limit for each major part and a second limit on the total number of minor tokens. It does not keep the rule for sharing the total, and the author later said the edge case was not covered by their tests. We keep the reported goal with two limits, and we share the budget from left to right so the result is always the same. Our version is about 72% the same as the reported question.

Continue the URL compression sequence. A path has major parts separated by / and minor parts separated by .. Base-compress a word by keeping its first and last character and replacing the middle with the number of omitted characters.

Each major may contain at most m output tokens, and the complete path may contain at most t output tokens. Every major must retain at least one token.

For this practice version, assign one token to every major first. Give the remaining global token budget to major parts from left to right, never exceeding m or that major's original minor-part count. Within a major with budget q, compress its first q-1 minor parts separately, concatenate all remaining original minor parts, and compress that concatenation as its final token.

The merge always uses original characters, not already-compressed text.

Practice sequence

  1. Part 1: compress every minor part
  2. Part 2: cap each major separately
  3. Part 3: enforce a global token budget (current)

Function

compressGlobal(s: String, m: int, t: int) → String

Examples

Example 1

s = "alpha.beta.gamma/delta.echo.foxtrot/golf.hotel.india"m = 2t = 5return = "a3a.b7a/d3a.e9t/g12a"

One token is reserved per major. The two remaining tokens go to the first and second majors, so their budgets are [2,2,1].

Example 2

s = "stripe.com/payments/checkout/customer.john.doe"m = 2t = 4return = "s7m/p6s/c6t/c13e"

There are four majors and four global tokens, so every major receives one token and merges all of its original minor parts.

Constraints

  • 1 <= m.
  • Let k be the number of major parts. k <= t <= the sum of all min(m, minorCount) values.
  • The input has no empty major or minor parts.
  • Every minor part has length at least 2.
  • The middle count may contain multiple digits.

More Stripe Onsite Interview questions

  • Parse Boolean Rule ExpressionsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Render a Task Tree from CSV RowsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Invoice / Payment ReconciliationPHONE 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

  • Choose the Next Hidden-Word GuessFlexport · ONSITE INTERVIEWFlexport interview questions
  • Count Lines in a Width-Limited DocumentGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Greedy and Beam Sentence DecodingMicrosoft · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
  • Format a Centered Newspaper PageVisa · OAVisa interview questions
  • Choose the Next Hidden-Word GuessCharacter.AI · PHONE SCREEN
  • Minimum Steps on a Circular Letter DialIBM · OAIBM interview questions
  • Text JustificationUber · PHONE SCREENUber interview questions
  • Word Wrap with Even JustificationSentry · OA · PHONE SCREENSentry interview questions
  • Max Number of OperationsSalesforce · OASalesforce interview questions
  • File System Shell CommandsHarvey · ONSITE INTERVIEWHarvey interview questions

Interview reports that mention this question

  • Stripe New Grad Interview Question Bank: 47 Problems

Stripe interview experiences

  • Stripe New Grad SWE OA and Phone Screen: 2 Experiences
  • Stripe Experienced SWE OA and Onsite Questions: 3 Experiences
  • Stripe SWE Intern Linked Merchants Team Screen: 1 Experience
  • Stripe OA: What It Tests (2026)
  • Stripe SWE Onsite over Two Days: 1 Experience
All Stripe interview questionsSee Stripe hiring insights
Saved
class Solution {
    public String compressGlobal(String s, int m, int t) {
      // write your code here
    }
}
Checking account…