Kth Letter of the Unpacked Text
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
2 <= len(packed) <= 60packedstarts with a letter and holds lowercase letters and the digits2to9- the finished text has at most
10**15letters 1 <= k <=the length of the finished text
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Strings problems
- Solve for xMedium
- String to IntegerMedium
- Substrings With Every VowelMedium
- Undo the Column ReadMedium
- Valid Decimal LiteralMedium
- Zigzag ConversionMedium
- Every Smallest Bracket RepairHard
- Expand the BracesHard