Aggregate Values by Letter
Updated
Problem statement
You are given a string encoded made of alternating uppercase English letters and positive decimal integers. A letter may appear more than once.
Sum all values associated with each letter. Return one string containing every letter that appears, in alphabetical order, immediately followed by its total.
For example, the two tokens B3 and B9 contribute B12 to the result.
Function
aggregateLetterValues(encoded: String) → StringExamples
Example 1
encoded = "A12B3C32B9"return = "A12B12C32"The totals are A = 12, B = 3 + 9 = 12, and C = 32. Writing the letters alphabetically produces A12B12C32.
Example 2
encoded = "Z5"return = "Z5"Only Z appears, so its value is returned unchanged.
Example 3
encoded = "C10A1C7B3A4"return = "A5B3C17"The repeated tokens give A = 1 + 4 and C = 10 + 7. The alphabetical order is A, B, then C.
Constraints
2 ≤ encoded.length ≤ 200000.encodedcontains one or more alternating tokens, each formed by one uppercase English letter followed by one or more decimal digits.- Every token value is in
[1, 10^9]and has no leading zero. - Every per-letter total fits in a signed 64-bit integer.
Similar questions at other companies
- Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesStripe · PHONE SCREENStripe interview questions
- Summarize Server Healthcheck LogsNVIDIA · PHONE SCREENNVIDIA interview questions
- Count Repeated WordsDatadog · PHONE SCREENDatadog interview questions
- Most Frequent Call Path From Function Trace LogsRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
- Video Cache Hit Rates from a CSV LogTubi · PHONE SCREEN
- Resolve Variable Equations with Dependency ErrorsApplied Intuition · PHONE SCREENApplied Intuition interview questions
- Chatbot Away-Status RefactorOpenAI · PHONE SCREENOpenAI interview questions
- Spreadsheet With Dependent CellsCharacter.AI · PHONE SCREEN
- Custom Record and Free-Form Field ParserNetflix · PHONE SCREENNetflix interview questions
- Chemical Formula WeightAgoda · PHONE SCREENAgoda interview questions