Ad
  • Custom User Avatar

    OP solved it, closing.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    It's impossible to read such code blocks, especially large ones - the best practice is to post using markdown so it is readable:

    Read here how to use the Codewars markdown for posting comments

    Also, since C isn't the most popular language on site, if you don't get a reply rapidly your best bet would be to ask in Codewars Discord (there is a dedicated help-solve channel and a dedicated C channel).

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Hi; as a general comment - on Codewars the "example tests" are on small input sizes; this is to allow you to troubleshoot your logic, make sure you understood the kata requirements etc.

    When you press Attempt, you will be tested against a (potentially very large) number of random tests on larger inputs - this will typically ensure that unoptimized brute force approaches time out.

    If your code works well but times out on Attempt, then you have found a working approach but not an efficient one - you need to optimize and/or redesign your approach.

    Since I don't use C/C++, I can't comment 100% on your current solution; but if the find instruction works by scanning through the entire string then your approach seems like it is O(n1 * n2 => n^2) to me where n1 and n2 are the sizes of the 2 strings.

  • Custom User Avatar

    Well, the answer is directly in the logs: "FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory".

    You hit the recursion limit and crashed the program. You won't go far with using recursion for this task.

  • Custom User Avatar

    How could we tell? We can't see your code.

    But it's possible that your code is too slow with your method.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    your solution contains undefined behavior (UB). it will randomly fail depending on the configuration of memory at the time your function is called. in check_begin_zeros(), you are iterating backwards on the input strings, stopping when you find a nul byte. what guarantees you that there will be a nul byte in memory before the start of the string ? if there isnt one, you will keep looping on the memory located before the string in memory.

    because of the very nature of C and UB it is not possible for the tests suite to check if your solution contains UB. this is not a kata issue.

  • Custom User Avatar

    Translating from OP's to English: tests for C seem to be incomplete because OP's solution fails one sample test with leading zeros (the cr_assert_str_eq(strsum("00001", "9"), "10");), but still passes random tests. Random tests for C probably have to be hardened to prevent incomplete solutions from passing.

  • Custom User Avatar

    [C] My solution gives all the expected tests but although I get an error in this test:
    "The expression (as strings) (strsum("00001", "9")) == ("10") is false: actual=580 expected=10".
    And this is not true!!!. My code gives "10":
    And my solution was indeed accepted and I got the score.
    So what will you do if this happens to you too?
    So. After you have clicked on test, you will see the error but just ignore it.
    Click on attempt and you will see that your solution has been accepted. (of course, if you don't have random errors).

  • Custom User Avatar

    To my opinion if you would solve the kata in C language you would see that in C it's not simple because of the exact dynamically allocation that you need

  • Custom User Avatar

    Sorry I got my mistake (only after I tried to attempt I got the right error).

  • Loading more items...