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 from result, if it exists.
  • A '#' duplicates the current result and appends it to itself.
  • A '%' reverses the current result.

Return the k^th character of the final string result. If k is out of the bounds of result, return '.'.

Example 1
Inputs = "a#b%*", k = 1
Output"a"
The final result is "ba", and the character at index k = 1 is 'a'.
Example 2
Inputs = "cd%#*#", k = 3
Output"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.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate