#Please check my code
Here’s the code
Still Wrong. Suggestion did not help.
Still test case 3 shows wrong answer.
@Doctor_Insult well the constraints are n,m< =1000 and your grid will not be able to accomodate that size, so try increasing it too. Rest of the logic is correct.
Why is that? If I’ve taken a 2D array of 1000*1000, it should be able to accomodate. I’ll try it nonetheless. But please explain why???
I increased the size, but now code shows run error. Segmentation fault often comes because of such big arrays. I don’t think array size is an issue…
@Doctor_Insult if size of col is 1000, you take input via getline, it will insert “\0” in the last place. Either take input for each character via cin. As for the memory issue, it is better to create arrays of big size using dynamic memory allocation because heap memory will be used instead of stack memory. You can make them a global variable as well. This is my accepted code as you can see the logic is same, the only thing that is different is the use of heap memory and difference in input method.