Ssegmentation fault

line 37, if u comment this code works,
why??
i need this statement in this code

Hey @officialharshit1996 which question code is this as you have raised doubt in dp wines problem. And the code doesn’t seems familiar to this problem.

https://www.codechef.com/LTIME91B/problems/SWAP10HG/

See a segmentation fault occurs when a program attempts to access a memory location that it is not allowed to access, or attempts to access a memory location in a way that is not allowed (for example, attempting to write to a read-only location, or to overwrite part of the operating system).
You have to check your logic before doing it in this way.

if i know, where i am stuck why should i ask?, line 37, if u comment this code works, why?? i need this statement in this code, problem in line 37 , what is it i don’t know

check the code, it is not very complex code, look u will understand


See for test case where string
S1 = 110100
S2 = 001011
Answer for this should be yes
Yours will give NO
0) 1) & 2) are the value of i where we are doing operations.

Moreover why your code isn’ working cause you haven’t code for all possible outcome.

What if your stack is empty. Empty stack top will pop out null and s[null] cannot be swap with s[i] This test case will run without segmentation fault. Because in this you will be having some value in stack

That’s why i told you this

Watch this video for solving this problem

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.