You are given a string compressed representing a compressed version of a string. The format is a character followed by its frequency. For example, "a3b1a1c2" is a compressed version of the string "aaabacc".
We seek a better compression with the following conditions:
Return the better compression of compressed.
Note: In the better version of compression, the order of letters may change, which is acceptable.
Example 1:
Input: compressed = "a3c9b2c1"
Output: "a3b2c10"
Explanation:
Characters "a" and "b" appear only once in the input, but "c" appears twice, once with a size of 9 and once with a size of 1.
Hence, in the resulting string, it should have a size of 10.
Example 2:
Input: compressed = "c2b3a1"
Output: "a1b3c2"
Example 3:
Input: compressed = "a2b4c1"
Output: "a2b4c1"
Constraints:
1 <= compressed.length <= 6 * 104compressed consists only of lowercase English letters and digits.compressed is a valid compression, i.e., each character is followed by its frequency.[1, 104] and have no leading zeroes.Solutions for this problem are being prepared.
Try solving it yourselfHow many LeetCode problems should you solve? #leetcode #techinterview #developer #softwareengineer • CrioDo • 304,695 views views
Watch 9 more video solutions →Practice Better Compression of String with our built-in code editor and test cases.
Practice on FleetCode