The "Better Compression of String interview question" is a data transformation task. You are given a compressed string like "a3b2a1". In this format, each character is followed by its count. However, the same character can appear multiple times (e.g., 'a' appears twice). Your goal is to "better" compress it by summing the counts of identical characters and returning the result in alphabetical order (e.g., "a4b2").
Goldman Sachs and Riot Games use the "Better Compression of String coding problem" to test a candidate's ability to parse strings and use frequency maps. It requires correctly handling multi-digit numbers (e.g., a10) and ensuring the final output is sorted. It evaluates "Hash Table interview pattern" and "String interview pattern" skills.
This problem follows the Parse and Aggregate pattern.
Input: "c2b5c10"
Map: {c: 2}.Map: {c: 2, b: 5}.Map: {c: 12, b: 5}."b5"."b5c12"."c12b5" because that was the order in the original string. The problem usually specifies alphabetical order.+ in a loop instead of a StringBuilder or list join.When parsing strings with mixed characters and numbers, always use a while loop inside your main loop to capture all consecutive digits. This ensures you handle multi-digit numbers correctly. This is a vital "String interview pattern" for parsing tasks.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Determine if Two Strings Are Close | Medium | Solve | |
| Minimum Deletions to Make String K-Special | Medium | Solve | |
| Minimum Number of Keypresses | Medium | Solve | |
| Minimum Number of Pushes to Type Word II | Medium | Solve | |
| Rank Teams by Votes | Medium | Solve |