SIGSEV in Twin Robots when using DP, AC using Recursion.

I was solving this problem:

It looked like a simple DP and I implemented it here:
However, it gives me a Segmentation Fault.

I tried to debug it and found that the problem is with this line:

int curr_value = grid[i][j] + grid[j][N - i - 1];

When I set it to 0, it gives me WA as expected.

Surprisingly, when I switched to Recursion + Memoization, it gives me an AC.
This is the solution using Recursion:

Can someone tell me why the first solution isn’t working?

Declare those , arrays global ,and as [2500].I too was earlier getting segmentation fault . I dont know if rest has error i not.

1 Like

Thanks! That worked somehow!

1 Like