Ad
  • Custom User Avatar

    -12 + (-18) = -30; the target is '6 - (-12) = 18' or '6 - (-18) = 24';

  • Custom User Avatar

    There is quite good solution, but it isn't consider values such as:

    • for s = 6
    • v1 = -12
    • v2 = -18

    So, 6 can be found by (-12 - -18) for example...

  • Custom User Avatar

    Practice. Don't listen to negative responses.

  • Custom User Avatar
  • Default User Avatar

    Your problem comes from the concept of proximity. The description says that we sould return the pair with the lowest last element's index. It means that in [10, 5, 2, 3, 7, 5] the answer is [3,7]. In [10, 5, 2, 3, 5, 7] the answer is [5,5] because the last 5 has an index lower than 7.

  • Custom User Avatar

    Yes, your code is even faster than mine

    Btw I check the performance on jsbench.me, it's a great site

  • Custom User Avatar

    hi, try my mine please, I think I achieved the best speed result

  • Default User Avatar
  • Custom User Avatar

    If you see what I have been trying to do in 3 days, you will advice me to quit.

  • Custom User Avatar

    Well, this one is more inspiring. For the kata, the algorithm complexity of solution can not be reduced. However this trick is somehow better than doing int comparison (as I once did), let alone adding up two numbers each time. On the other hand, utilizing the set type also involves consideration of the feature of python language, which is good.

  • Custom User Avatar

    shorter not always better 🙂

  • Default User Avatar

    It should be parsed from left side and that means [4,3] shoud be the first result instead of [5,2]. But maybe the description is not clear enough for me :-)

  • Default User Avatar

    Yeah I don't think it would time out since n is being divided smaller like tacoslayer said. You are right that there's no need to keep iterating once it has reached the square root of the number,

    BUUUUuuuuut, because this algorithm divides n each time it finds a factor, it will usually get cut short before then anyway. It would only iterate all the way through when n has been reduced to a prime number. not really such a problem generally... but there's no reason not to cut it off at the square root since not all prime numbers are small........it'd be the difference for example between iterating 151051 times and iterating only 388 times.

  • Custom User Avatar

    I think I didn't understand what I had to do in this Kata because if this is the solution you're only checking the next and guesses the answer but it doesn't really check if that was the best or correct answer.

    In the example:

    [10, 5, 2, 3, 7, 5], 10

    If I move the last five one step back the result is [5,5].

    But the real answer is still [3,7] because the difference in proximinity is (5 - 4) = 1 vs (5 - 1) = 4.

    Not convinced by this answer at all it just hacks the tester.

  • Default User Avatar

    i didn't understand why we ceil the result , why can't we just floor it

  • Loading more items...