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.
What happens, when n exceeds the size of p?
Beautiful :)
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: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.
This comment is hidden because it contains spoiler information about the solution
The first one.
4 (2+avg 10 30) = 13.0
Which one is required now?
4 (2+avg 10 30) = 13.0
or(avg 4 2) + (avg 10 30) = 23.0
? Thanks really.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).
Sure, I understand that's a decision that's been made, but I really don't share that view.
In all cases, kyus are shared between languages.
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.
Time complexity is O(n). The image is scanned two times at most.
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 :)
I see two issues:
Firstly, the code modifies the image that is passed (
globimage.pixels
points to the same place asimage.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).This comment is hidden because it contains spoiler information about the solution
Loading more items...