Skip to the code
cf.
+10 XP

#623 Expand a Compressed Label

easy

A barcode label printer receives text in a compact form: a count followed by one character, repeated. 3a2b means aaabb. Counts can have several digits, so 12x means twelve x characters.

Write expandLabel(code) that returns the full text. Every character in the output is a non-digit, and each one is preceded by its count. An empty code gives an empty string.

Example 1

Input: code = "3a2b"
Output: "aaabb"

Three a, then two b.

Example 2

Input: code = "12x1y"
Output: "xxxxxxxxxxxxy"

The count 12 has two digits.

Constraints

  • 0 <= code.length <= 1000
  • Every count is between 1 and 1000.
  • The expanded text has at most 10^5 characters.
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).