Back to Month
MEDIUM 16 Jun 2026

3612. Process String with Special Operations I

</> Solution

class Solution {
    public String processStr(String s) {
        StringBuilder result = new StringBuilder();

        for (char ch : s.toCharArray()) {

            if (ch >= 'a' && ch <= 'z') {
                result.append(ch);
            }
            else if (ch == '*') {
                if (result.length() > 0) {
                    result.deleteCharAt(result.length() - 1);
                }
            }
            else if (ch == '#') {
                result.append(result.toString());
            }
            else if (ch == '%') {
                result.reverse();
            }
        }

        return result.toString();
    }
}

TIME COMPLEXITY

O(n + k)

SPACE COMPLEXITY

O(k)

TOPICS

String