← Questions

Compress URL path segments under token limits

0
StripeCodingLast asked Nov 2023

A path such as alpha.beta.gamma/delta.echo has major parts separated by / and minor parts separated by .. A word is compressed by keeping its first and last letters and replacing the middle with the count of letters removed (alpha becomes a3a).

  1. Compress every minor part.
  2. Each major part may produce at most m tokens: compress its first minor parts one by one and merge the rest into one final token, compressed from the original letters.
  3. The whole path may produce at most t tokens: every major part keeps at least one, and the remaining budget is handed out from left to right.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding