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.
-42
The code is practically inefficient, what if the array is very large with only one number?, will you reserve all that space just for one number?
This comment is hidden because it contains spoiler information about the solution
Hey, I am still learning c and was wondering if you could use sprintf instead?
Ha, didn't know about asprintf(), and overlooked it when looking at snprintf() manpage, thanks!
When you first encounter a dup and clear "count2" variable why do you keep searching the pResult array?
this decition is very safety. Goood job!
Ohhh boy! youve really gone that route!
Undefined behavior is neither best practice nor clever.
Yeah, how returning pointer to stack got top score in best practices is beyond me...
can someone answer where the function findIndex() comes from. this isnt in the standard lib
Functions "findIndex" and "rotate" are non-standard and also not available in the viewable code. So how can everyone come to this solution?
Oka, since C99 yes, you can. But you can't define it:
int array[n]; // it's ok.
int array[n] = {0}; // this fails.
error: storage size of ‘newArray’ isn’t constant
You cannot specify the storage size of a static object at runtime.
The test cases for this kata do not
free
the returned memory - the only sensible option is to mutate the input (array
) and return it.Correct is never best practice to return a stack allocated variable.
This will fix it, that is unless you are threaded - as this isn't thread safe.
static int newArray[length];
Loading more items...