Save Gotham! question in geeks for geeks

when i ran in coding block ide then it run but in geeks for geeks it show sometime segmentation fault why?
code link-https://ide.codingblocks.com/s/166506

Hi @17manishms
See in your code in the else case you are popping element from s2 stack but in the condition of while loop you have only mentioned that !s1.empty() but when s2 gets empty first and then your try to access s2.top() then it gives you segmentation fault error. So just add condition that !s2.empty() in the while loop with &&.

Hi @17manishms
Mark your doubt as resolved if you if you get what was wrong with you code.

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.