Ad
  • Custom User Avatar

    closing as a user error and not an issue within the tests

  • Custom User Avatar

    You are mutating the array array because of a buffer overflow. Note that sizeof do not return the number of elements in an array but the size in bytes of its operand. So an array of 4 ints will have a size of 16 bytes because each int has a size of 4 bytes.

    Just fix this minor issue and your code pass :)

  • Custom User Avatar

    Random test cases in C have multiple integers with odd count but description says test cases shouldn't
    examples:
    for array = {7, 1, 7, 75, 75, 1, -11, -11, 7, 7, 75, -11, -11, -11, -11, 7, 7, 7, 1, 1, 75, 7, -11, 75, 75, 1, 75, 75, -11, 75, 1}
    expected 1 but got 75
    for array = {59, -34, 59, 59, 59, 59, 59, 59, 59, 59, 59, -34, -34, 59, 59, -34, -34, 59, 59, 59, -34, -34, 59, 59, 59, 59, 59, -36, 59}
    expected -36 but got 59

  • Custom User Avatar

    The problem is in your code. In a for loop, you are assigning characters to subarray by index using strlen(subarray) as your index. Essentially, assign the character to the last index of the subarray, but that doesn't quite work. strlen works by finding a null terminator to find the end of the string, but you aren't null terminating on every iteration of the loop, so sometimes strlen(subarray) will return the incorrect length. I printed out the length of subarray on every iteration of the loop. Here's a log from a test that failed in this way:

    for string:
    "oyyeqqcu enfmzat t myu jqtqrqem ekm dqrf fm emdo"
    expected:
    "oyyeqqcu"
    but got:
    "o��yyeqqcu"
    
    
    oyyeqqcu enfmzat t myu jqtqrqem ekm dqrf fm emdo
    before loop - subarray strlen: 0
    subarray strlen: 4
    subarray strlen: 5
    subarray strlen: 6
    subarray strlen: 7
    subarray strlen: 8
    subarray strlen: 9
    subarray strlen: 10
    subarray strlen: 11
    subarray strlen: 12
    

    Those subarray strlens are printed directly after the assignment of each character, and this log is only for the first word in str "oyyeqqcu". So, it assigns o to subarray at index 0 first, and immediately afterwards, strlen reports that subarray has a length of 4, which is obviously not what you want.

  • Custom User Avatar

    I just copied your current solution, removed the free(subarray); line and it worked.

  • Custom User Avatar

    I've been trying to code a solution in C but on the random tests after it has ran a few times it begins inserting 3 random characters after the first letter of what would be the result. The test cases it fails on run fine in other compilers but I run into this bug everytime.
    example:
    for string:
    "wrrwzf tky e nyjhrr qm cjitfy xxz tav"
    expected:
    "wrrwzf"
    but got:
    "w�4:rrwzf"