I am getting run-time error in one case. I can’t figure it out.
Run Time error in prateek sir and coding
There is problem with your stack you have made . When top == arr.length , then you are making a new array the copying the elements to the new array . This should be done when top == arr.length - 1 , otherwise it will try to access size of array , which will give index out of bounds exception
Moreover you can optimize the code . You have used array of stack and stored exactly one element in one stack in stack array , there was no need of doing that , you could simply use a single stack and do the same push and pop operations on it according to the input.
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.