Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
OP solved it, closing.
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).
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.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.
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.I guess you tried your code in your IDE outside CodeWars, and there you should call your function not once, but more than once like it is tested here:
If you call it that way, you'll get a different value for the second test, instead of
"10"
Your solution has a bug, it does not work correctly for inputs longer than 100 digits.
Bug in your solution is not a kata issue.
C is not my cup of tea, but did you try calling your function several times in a row? Commenting out the first sample test, the second one, works. The third one fails tho no matter what, so, that looks like a problem with your code, and not a kata issue.
Read this: https://docs.codewars.com/training/troubleshooting/#works-but-no
Please see here how to use code formatting: https://docs.codewars.com/references/markdown#code-block
Having the code formatted would be really helpful.
I am stuck with the same issue: "double free or corruption (out)". Were you able to solve this?
Language is C, and your code also fails regularly on some random tests (though not always). It's probable your function has some default somewhere and that it writes out of a regularly allocated space. This is a very common error in C (just search this on Google and you will see), it's impossible to answer you without more elements.
Which language?
Read this: https://docs.codewars.com/training/troubleshooting/#post-discourse and this: https://docs.codewars.com/training/troubleshooting/#works-but-no
Your problem is you're using a global var.
Please read this: https://docs.codewars.com/training/troubleshooting