Process String with Special Operations I

You are given a string s consisting of lowercase English letters and the special characters: *, #, and %.

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 final string result after processing all characters in s.

Example 1
Inputs = "a#b%*"
Output"ba"
After appending, duplicating, appending, reversing, and removing the last character, the final result is "ba".
Example 2
Inputs = "z*#"
Output""
After removing z, duplicating the empty string still leaves the final result as "".

Constraints

  • 1 <= s.length <= 20
  • s consists of only lowercase English letters and special characters *, #, and %.

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