Back to June Back to Year 2026
MEDIUM 16 Jun 2026 View on LeetCode

3612. Process String with Special Operations I

</> Solution

/**
 * Problem: LeetCode 3612 - Process String with Special Operations I
 * Difficulty: Medium
 * Language: Java
 * Author: CodeByTushu
 */
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 * L)

SPACE COMPLEXITY

O(L)

TOPICS

Simulation String