FunctionRacerProblemsRace

Kth Letter of the Unpacked Text

MediumStringsPython, JavaScript, TypeScript, Java, C++

packed is read from left to right to build a text. A letter is added to the end of the text. A digit d (from 2 to 9) replaces the text built so far by d copies of it, one after another. So ab2c3 builds ab, then abab, then ababc, then ababcababcababc.

Return the k-th letter of the finished text, counting from 1. The finished text can be far too long to build.

Example 1

packed "ab2c3"
k 8
returns "a"

The finished text is ababcababcababc, and its 8th letter is a.

Example 2

packed "a9999"
k 5000
returns "a"

The text is the letter a written 9 * 9 * 9 * 9 = 6561 times.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Strings problems