In the May20 Cook contest, there was a problem on Strings (CHEFSHIP).
I am using Z-algorithm to solve this, and below are two solutions with only one diff -
- AC Code on passing string by reference - code1-accepted
- SIGSEGV on same code when passing string by value - code2-sigsegv
Also, the SIGSEGV gets fixed if I check
i+i < n and
n-2*i >= 0.
Check how this SIGSEGV goes away here on code3-sigsegv-fixed.
This is weird, how can passing a string by value generate wrong z-array?