Aggregate Letter-Number Groups

Quick Overview

Parse a string of letter-number groups, sum all numbers for each letter, and return groups sorted by letter; for example, repeated B groups are combined into one total.

Aggregate Letter-Number Groups

Company: Riotgames

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

# 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"` ```hint Detect group boundaries A new uppercase letter ends the previous numeric token and starts the next accumulator key. ```

Overview: Parse a string of letter-number groups, sum all numbers for each letter, and return groups sorted by letter; for example, repeated B groups are combined into one total.

|Home/Coding & Algorithms/Riotgames
Riotgames logo
Riotgames
Aug 26, 2026
easySoftware EngineerTechnical ScreenCoding & Algorithms
0
0

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"

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...