Ad
  • Custom User Avatar

    What happens, when n exceeds the size of p?

  • Custom User Avatar
  • Custom User Avatar

    As stated in the solution set up, you must report the size of your output to the parameter *tree_size before returning your answer, it is not given:

    int *tree_by_levels (const Tree *tree, size_t *tree_size)
    {
      *tree_size = 0; // report the tree size
      return NULL; // return a heap-allocated array, it will be freed
    }
    
  • Custom User Avatar

    The tests seem broken for C. The parameter tree_size isn't passed correctly.
    If I print the value of tree_size, which should be 8 for the first test case, I get zero. This means that I get a result array of size zero and fail the test case.
    But if I manually assign the value 8 to it, I pass the test case.

  • Custom User Avatar

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

  • Custom User Avatar

    The first one.

    4 (2+avg 10 30) = 13.0

  • Custom User Avatar

    Which one is required now? 4 (2+avg 10 30) = 13.0 or (avg 4 2) + (avg 10 30) = 23.0? Thanks really.

  • Custom User Avatar

    It's not a question of view, that's how CodeWars is designed and it would be impossible in another way. That would mean to open a beta validation process for each of the more than 50 languages currently available, with reviewers for all of them. That would last ages, causing a great amount of useless duplicate work and simply wouldn't be manageable (most languages count with a small number of active users involved, and they are often the same ones across least common languages).

  • Custom User Avatar

    Sure, I understand that's a decision that's been made, but I really don't share that view.

  • Custom User Avatar

    In all cases, kyus are shared between languages.

  • Custom User Avatar

    Imo this is a 4 kyu in python, but a 3 kyu in c or java if one insists on finding the shortest path.
    To be fair, I think it's strange to maintain the same kyu for different programming languages in cases like these.
    Also, the description shoud clearly state that there could be more than one exit.

  • Custom User Avatar

    Time complexity is O(n). The image is scanned two times at most.

  • Custom User Avatar

    Thanks for the feedback. The code wasn't efficient and I did a lot of unnecessary work. I optimized it, and now it works fine. Nice kata :)

  • Default User Avatar

    I see two issues:

    Firstly, the code modifies the image that is passed (globimage.pixels points to the same place as image.pixels). This is going to cause problems in situations where the tests ask about multiple colours on the same image. The sample tests are such a situation; this is why the code fails the second sample test.

    Secondly, your algorithm is O(n^1.5), not O(n) (where n = number of pixels). Imagine what would happen if the image were a k by k square (so n=k^2) with all pixels the same colour.
    Your function insideDepthBorders will be called k^2 times on the first iteration, then (k-1)^2 times the second iteration, then (k-2)^2 times the third iteration, etc. The total number of calls is O(k^3); that is, O(n^1.5).

  • Custom User Avatar

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

  • Loading more items...