Ad
  • Custom User Avatar

    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

  • Custom User Avatar

    Problems with performance of tests were cased by a fu broken implementation of shuffle, should be fixed now.

  • Custom User Avatar

    Tried, but in vain.

  • Custom User Avatar

    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.

  • Custom User Avatar

    Usually mathematical expressions like this are calculated left to right so it would be 2 * 3 = 6

  • Default User Avatar

    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.

  • Custom User Avatar

    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. =)

  • Custom User Avatar

    "i" can not be "0"! because I used IntStream which starts from "1"
    IntStream.range(1, arr.length)

  • Custom User Avatar

    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