runtime error (SIGSEGV) in infinite grid game

for this question , i am getting runtime error(SIGSEGV) with this solution . but there are many successful submissions in C for this problem which also uses same amount of memory as i did that is 2-d array of around 1000*1000, like this what is the problem with my solution ?

This seems to me as the problem

while(x<=1000 || y<=1000) // Problem lies here








If either of x or y become > 1001 then you’ll access element which has not been allocated as your char array has dimensions 1002 * 1002, it should be “&&” instead of “||”. Hence the Runtime Error.


Ouditchya Sinha.

1 Like

can you tell me why i am getting wrong answer with this solution for the above question?

@seekay: I think your logic is wrong. I have printed your array here - Try to think of small test cases, you’ll realise your mistake.
All the Best. :slight_smile:

The link appears to be broken, just try printing your “a” array & cross check for small cases with pen & paper.

This is the link :