Practice/Google/Leetcode 394. Decode String
CodingMust
You are given an encoded string where certain substrings are marked for repetition using a special notation. The encoding format is k[substring], where k is a positive integer indicating how many times the substring should be repeated.
Your task is to decode and expand the entire string by processing all encoded patterns, including those that are nested within other patterns.
The encoded string follows these rules:
10, 25)[ and ] delimit the substring to be repeatedReturn the fully decoded and expanded string.
[ ]Example 1:
Input: s = "3[a]2[bc]" Output: "aaabcbc" Explanation: "3[a]" expands to "aaa", and "2[bc]" expands to "bcbc". Concatenating gives "aaabcbc".
Example 2:
Input: s = "2[ab3[c]]" Output: "abcccabccc" Explanation: Start from innermost: "3[c]" becomes "ccc". Then "ab3[c]" becomes "abccc". Finally "2[abccc]" produces "abcccabccc".
Example 3:
Input: s = "x2[y]z" Output: "xyyyz" Explanation: The 'x' is literal, "2[y]" expands to "yy", and 'z' is literal.
Example 4:
Input: s = "10[a]" Output: "aaaaaaaaaa" Explanation: Multi-digit number 10 means repeat 'a' ten times.