Tap here to switch tabs
Problem
Submissions

Problem: Better Compression of String

med
30 min
Try to solve the Better Compression of String problem.

Statement

You are given a string compressed that represents a compressed string format where each character is followed by its frequency.

Create a better compression of the string such that:

  • Each distinct character appears exactly once.

  • The characters are arranged in alphabetical order.

  • Each character is directly followed by the sum of all its frequencies from the original string.

Return the better compressed string.

Constraints:

  • 1≤1 \leq compressed.length ≤6imes104\leq 6 imes 10^4

  • compressed consists only of lowercase English letters and digits.

  • compressed is a valid compression, where each character is followed by its frequency.

  • Frequencies are in the range [1,104][1, 10^4] and have no leading zeroes.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Better Compression of String

med
30 min
Try to solve the Better Compression of String problem.

Statement

You are given a string compressed that represents a compressed string format where each character is followed by its frequency.

Create a better compression of the string such that:

  • Each distinct character appears exactly once.

  • The characters are arranged in alphabetical order.

  • Each character is directly followed by the sum of all its frequencies from the original string.

Return the better compressed string.

Constraints:

  • 1≤1 \leq compressed.length ≤6imes104\leq 6 imes 10^4

  • compressed consists only of lowercase English letters and digits.

  • compressed is a valid compression, where each character is followed by its frequency.

  • Frequencies are in the range [1,104][1, 10^4] and have no leading zeroes.