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.
this is an issue within your code, not the kata
two problems here :
result[-1] = '\0'
, that's an out of bounds write:pos
should have enough space to handle 2 digits + 1 space + 1 nul terminator = 4 chars, but you wrotechar pos[3];
You could actully start the inner loop with j = 1 as you already have established that nums[i][0] is the smallest value before entering the loop.
Clever solution and well optimized! I see others have arrived at this solution, but your comments stand out.
Seems there is a memory allocation thing going on here.
I'm coding in C.
The number tests pass, the first string test pass but then:
Test Results:
number_tests
should_pass (2 of 2 Assertions)
Completed in 0.5602ms
sample_cases
should_pass_all_the_tests_provided
Test Passed
Incorrect answer for input: "The narwhal bacons at midnight."
Actual: "3 11" fixture.c (ڔ��؊20 8 5 14 1 18 23 8 1 12 2 1 3 15 14 19 1 20 13 9 4 14 9 7 8 20"
Expected: "20 8 5 14 1 18 23 8 1 12 2 1 3 15 14 19 1 20 13 9 4 14 9 7 8 20"
It looks like my buffer is filled with garbage on the second run. It works on my local machine, gcc 9.3.0. on xubuntu 20.04.
Any ideas anyone? Error in the test framework?
Oh, didn't know that about the calloc, thank you for pointing this out!
result[size] = '\0'; is not needed as calloc nullifies the allocated memory.
function isupper() could be used instead of string[index] >= 'A' && string[index] <= 'Z'.
Nice solution though
tnx, i appreciate it.
You should free 'temp'. Caller cannot do it-
For 'marker' you could use char instead of int to save space. Also remember to free 'marker' as the caller cannot do that.
Neat, but wastes memory. A 125 char array is created.
Nice. Actually you could skip the last test ' if (i*i < n)'