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.
According to the condition of the problem, the length of the array is guaranteed to be > 1, in the examples it can be seen that the first element in the incoming array is "thrown out", this is logical, because checking for i % 0 will not make sense. That's why we start the sequence with 1
Problems with performance of tests were cased by a
fubroken implementation ofshuffle
, should be fixed now.Tried, but in vain.
C version generally works, but tests seem to go over the top a bit and oscillate on the edge of timeout. Your solution has to be quite performant to pass.
I will take a look tomorrow if something can be improved wrt timeouts or tests feedback, but even if amount of tests will be cut in half, solutions with complexity worse than linear will most certainly timeout.
Usually mathematical expressions like this are calculated left to right so it would be 2 * 3 = 6
At least in the Javascript version I authored, if something's not valid, e.g. jump to label that doesn't exist, it's expected that an exception be thrown.
That's right. Thanks for pointing out. I guess that I have excluded index 0 out of a rush so the modulo operation wouldn't fail with a division by zero error but didn't event think about that there exists a multiple of 0.
It's a very good example of how quickly wrong code can evolve out of a simple task and also pass unit tests and potentially go into production. And it would do without good code reviews like this one. =)
"i" can not be "0"! because I used IntStream which starts from "1"
IntStream.range(1, arr.length)
you only need to look to the right side and the element to the left of each element, can be easily achieved with pattern matching