#880
Decoded String at Index
expert · 1050 · lc medium +32 · verified · 37.3% accepted · 2,612 likes · top 15%
Description
You are given an encoded string s. To decode it, process each character left to right:
- If the character is a letter, write it onto a conceptual tape.
- If the character is a digit d, repeat the current tape d - 1 additional times.
Given a 1-indexed integer k, return the kth character of the fully decoded tape.
Example 1:
Input: s = "leet2code3", k = 10
Output: "o"
Explanation: The decoded string is "leetleetcodeleetleetcodeleetleetcode".
The 10th letter in the string is "o".
Example 2:
Input: s = "ha22", k = 5
Output: "h"
Explanation: The decoded string is "hahahaha".
The 5th letter is "h".
Example 3:
Input: s = "a2345678999999999999999", k = 1
Output: "a"
Explanation: The decoded string is "a" repeated 8301530446056247680 times.
The 1st letter is "a".
Code
1
2
3