Ad
  • Custom User Avatar
    int len1 = strlen(a)-1, len2 = strlen(b)-1, add = 0;
    char* ans = malloc(sizeof(char)*(len1+len2));
    

    for "8" + "9", this will allocate 0 bytes of memory, while 3 are needed.

    what makes your code crash however it the fixed test with an empty string (which should not exist, but that's a separate issue already reported here

  • Custom User Avatar

    Your solution has a bug. For some inputs it returns a non-freeable buffer, and tests crash on attempt to free it.

  • Custom User Avatar

    C
    testcase: strsum("99999999999999999999999999999", "9999999999999999999"), "100000000009999999999999999998"
    My code passes when I use the same testcase on the sample tests, yet I receive a "Caught unexpected signal: SIGSEGV (11). Invalid memory access." when attempting the generic tests.
    What could be the problem?