Ad
  • Default User Avatar
  • Default User Avatar

    I am blown away by the solution :D

  • Custom User Avatar

    If you're gonna add type hints, go all the way:

    def sum_array(a: list[int]) -> int:
        return 0
    

    Also, the # your code here is 100% optional, I personally find it unnecessary. The "should be runnable" thing would be nice though.

  • Default User Avatar

    It actually took me quite a bit to understand why :'D
    Thanks

  • Default User Avatar

    your code is almost correct now, but you are not handling an empty array correctly

  • Default User Avatar

    You can ignore any need to sanitize words or add punctuation

    So it is guaranteed that there wont be spaces inside the words

  • Default User Avatar

    you do not allocate enough memory. count is the length of the input array, i.e. the number of strings. your string will always require more memory than that, for example if you join "ab" and "def" you need 2 ("ab") + 1 (space) + 3 ("def") + 1 (nul terminator) = 7 bytes. you need to calculate the correct buffer size before allocating memory.

  • Default User Avatar

    what is the point of your while (result_index < char_num) loop ? you already have the correct string at the end of the enclosed for loop. Having the while loop makes your program concatenate the same string several times, so you write e.g. "a b c d a b c d" instead of just "a b c d" (and your buffer is not large enough for that, hence the segfault)

  • Default User Avatar

    I am attempting this in C, the single string test case always fails with seg fault.
    I tried to return *words when count==1, not working. Can anyone be so kind so as to explain this to me?

  • Default User Avatar

    i'm new to programming and i was wandering how can you write the codes in a comment like you did with that box and colors? i tried copy and paste but it comes as a text and without than box? thanks in advance!

  • Custom User Avatar

    Very simple :D

  • Custom User Avatar

    Yes, it work now.
    @monadius, thank you very much!

  • Custom User Avatar

    I updated Dart random tests. Now reduce should work.

    Dart random tests called the solution function with an argument of type List<int>. I changed this type to List<num>. Dart allows List<int> when List<num> is expected because all generic parameters are covariant in Dart and so List<int> is a subtype of List<num>. On the other hand, List<E>.reduce(E combine(E, E)) has a contravariant argument (the return value of combine). That's why it was impossible to use reduce before (all generic arguments of fold are covariant so there were no issues with it).

  • Custom User Avatar

    *Post edited for not being helpful*

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Loading more items...