Recursion is a great tool to have available when dealing with some problems, but each recursive call carries a cost. The cost depends on the language being used, and perhaps the OS architecture. As a consequence, the usefulness of recursion is limited by the circumstances in which the recursion is applied. In Java each function call typically costs a number of kilobytes of memory as that's the size of the stack frame (and each call requires a new stack frame). Also, in Java, the stack size (memory) is pre-allocated as part of the VM settings ([see `-Xss` commandline option](https://docs.oracle.com/javase/9/tools/java.htm#JSWOR624)) Other languages (for example, Go) have a much cheaper mechanism for stack management, and thus the cost of recursion is reduced. Java typically cannot go further than a few thousand calls deep in the stack, Go can go millions of calls deep. In your use case, the depth of the stack is proportional to the length of the input string, and strings longer than a few thousand characters will cause an out-of-memory problem. Bottom line, is that recursion is not the solution to use for your problem. Even in other more stack-friendly languages I would still avoid recursion. Solve it iteratively, using a `StringBuilder`, a [`Reader`](https://docs.oracle.com/javase/8/docs/api/java/io/Reader.html#read--), and an if-statement... public static String fix(Reader reader) { int ch; StringBuilder result = new StringBuilder(); while ((ch = reader.read()) >= 0) { if (ch == '<') { result.setLength(result.getLength() - 1); } else { result.append((char)ch); } } return result.toString(); }