Ad
  • Default User Avatar

    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 (hence sumRight += digits[n-i-1] -- note the n-i subtraction).

  • Default User Avatar

    Will you consider the Uppercase letter the same as the lowercase version or a different one?

  • Default User Avatar

    Still, not the best practice in C. I think is not a big deal just put there a comment above the function declaration.

  • Default User Avatar

    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.

  • Default User Avatar

    How is this a Best Practice?
    For this particular use of the function is not necessary to allocate a global var.

  • Default User Avatar

    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.