Skip to the content

The echo spell

Problem

In the tower of Velmira, long spells are jotted down in short so they fit on the scroll: 3a2b means a three times and b twice. The tower's echo reads the note and recites the whole spell, aaabb.

Write a function that takes the note and returns the full spell as a string. The note is a row of pairs: a number and a lowercase letter. The number is always there and can have several digits, so 12z is twelve z, not one and then two. With 2k10e you return kk followed by ten e: kkeeeeeeeeee. A 0 means that letter stays silent: 0a3b returns bbb. With an empty note you return an empty string.

Examples

  • Two pairs

    "3a2b" → "aaabb"

  • Each letter once

    "1s1t1a1r" → "star"

  • A two-digit number

    "12z" → "zzzzzzzzzzzz"

  • An empty note

    "" → ""

Besides these, the challenge has hidden tests that are revealed when you submit your solution.

You start with this

Python

def echo_spell(note):
    pass

JavaScript

function echoSpell(note) {
}
Solve this challenge

It opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.

More O(n) challenges

See all challenges →