Process String with Special Operations II
You are given a string s consisting of lowercase English letters and the special characters '*', '#', and '%'.
You are also given an integer k.
Build a new string result by processing s according to the following rules from left to right:
- If the character is a lowercase English letter, append it to
result. - A
'*'removes the last character fromresult, if it exists. - A
'#'duplicates the currentresultand appends it to itself. - A
'%'reverses the currentresult.
Return the k^th character of the final string result. If k is out of the bounds of result, return '.'.
Example 1
Input
s = "a#b%*", k = 1Output
"a"The final
result is "ba", and the character at index k = 1 is 'a'.Example 2
Input
s = "cd%#*#", k = 3Output
"d"The final
result is "dcddcd", and the character at index k = 3 is 'd'.Constraints
- 1 <= s.length <= 10^5
- s consists of only lowercase English letters and special characters '*', '#', and '%'.
- 0 <= k <= 10^15
- The length of result after processing s will not exceed 10^15.