Aggregate Letter-Number Groups
Implement aggregate_letter_numbers(encoded: str) -> str.
encoded is a concatenation of groups. Each group is one uppercase English letter followed by one or more decimal digits representing a nonnegative integer. Sum the numbers belonging to the same letter. Return one group per distinct letter in alphabetical order, with the letter followed immediately by its decimal total and no separators.
Valid Input Domain
-
The input is a valid concatenation of at least one group.
-
Numeric tokens have no sign and fit in a signed 64-bit integer.
-
Each per-letter sum fits in a signed 64-bit integer.
Constraints
-
2 <= encoded.length <= 500,000
Public Examples
Example 1
Input: "A12B3C32B9"
Output: "A12B12C32"
Example 2
Input: "Z1A2Z10"
Output: "A2Z11"