Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    3614 - Process String with Special Operations II.

    Hard

    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 letter 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 <code>k<sup>th</sup></code> character of the final string result. If k is out of the bounds of result, return '.'.

    Example 1:

    Input: s = "a#b%\*", k = 1

    Output: "a"

    Explanation:

    The final result is "ba". The character at index k = 1 is 'a'.

    Example 2:

    Input: s = "cd%#\*#", k = 3

    Output: "d"

    Explanation:

    The final result is "dcddcd". The character at index k = 3 is 'd'.

    Example 3:

    Input: s = "z\*#", k = 0

    Output: "."

    Explanation:

    The final result is "". Since index k = 0 is out of bounds, the output is '.'.

    Constraints:

    • <code>1 <= s.length <= 10<sup>5</sup></code>

    • s consists of only lowercase English letters and special characters '*', '#', and '%'.

    • <code>0 <= k <= 10<sup>15</sup></code>

    • The length of result after processing s will not exceed <code>10<sup>15</sup></code>.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Character processStr(String s, Long k)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait