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.
Variable n contains the number of digits of the input number, it is incremented in
digits[n++] = number % 10;
.The comparison in the later loop is between the current iteration aka digit with the total digits n (minus 1 because i starts at 0) and divided by two because you are "cutting" the input number in two halfs: the left and the right one, so your sums will be only between the n/2 digits from each side.
The left digits sum is performed from left to right (hence
sumLeft += digits[i]
) and the right digits sum is performed from right to left (hencesumRight += digits[n-i-1]
-- note the n-i subtraction).Will you consider the Uppercase letter the same as the lowercase version or a different one?
Still, not the best practice in C. I think is not a big deal just put there a comment above the function declaration.
Yes, I know that those functions (array2StringData and sortedList) are not to use in the implementation.
What I'm saying is that is not explicit that the memory allocated by our implementation (cartesian_neighbor) will be freed afterwards.
If I'm allocating memory in my functions, I like to know if that memory is then freed in the program, so to avoid memory leaks.
A simple comment above the cartesian_neighbor declaration should be enough.
See, for example, https://www.codewars.com/kata/directions-reduction/discuss/c test case.
How is this a Best Practice?
For this particular use of the function is not necessary to allocate a global var.
In C, you should state that the returned array is deallocated after is used by the other functions.
This is not clear in the test cases.