Stack Overflow Error

I used StringBuilder instead of String as that was causing timelimit error.
But while taking StringBuilder I am facing StackOverFlow Error.
Please look into the code,

Please post your code. I can’t access it.

The Stack Overflow Error doesn’t occur due to StringBuilder . Your Recursion doesn’t terminate peacefully. Please look into it.

I am adding one character at a time. So I think my base case is correct.What am I missing ?
Please tell it.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

Parameters and local variables are allocated on the stack . The stack typically lives at the upper end of your address space and as it is used up it heads towards the bottom of the address space. Your process also has a heap, which lives at the bottom end of your process. As you allocate memory, this heap can grow towards the upper end of your address space. As you can see, there is a potential for the heap to “collide” with the stack. If there is no space for a new stack frame then, the StackOverflowError is thrown by the Java Virtual Machine (JVM).

  • If the stack is full you can’t push, if you do you’ll get stack overflow error.
  • If the stack is empty you can’t pop, if you do you’ll get stack underflow error.