6 kyu

N smallest elements in original order (performance edition)

170 of 277FArekkusu
Description
Loading description...
Algorithms
Arrays
Performance
  • Please sign in or sign up to leave a comment.
  • imtinochet Avatar

    This comment has been hidden.

  • ahmet_popaj Avatar

    Very nice kata on dynamic programming and algorithms optimization for the record, well done.

  • user6793616 Avatar

    It seems like all the inputs have non-negative integers within the 0..2³² range. Yet the kata just speaks of integers. Would it not be good to include negative and bigger integers as well? I see some JavaScript solutions work on the assumption that there are no such integers in the input.

  • ddejohn Avatar

    Super confused by the tests and the description. Are we taking the first n unique minimum elements? Or just the first n of the sorted elements? Or something else entirely? My current solution only deviates in the last few elements of these long lists, which seems like super strange behavior to me. An example:

    [6, 1, 2, 6, 4, 7, 4, 6, 5, 7, 6, 3, 6, 7, 3, 8, 1, 8, 4, 8, 7, 8, 4, 8, 6, 7, 4, 8, 8, 1, 4, 2, 1, 8, 4, 6, 6] # mine
    [6, 1, 2, 6, 4, 7, 4, 6, 5, 7, 6, 3, 6, 7, 3, 8, 1, 8, 4, 8, 7, 8, 4, 8, 6, 7, 4, 8, 8, 1, 4, 2, 1, 4, 6, 6, 1] # correct
                                                                                                        ^ first deviation, what would cause this?!
    

    In the "correct" solution you can clearly see that an 8 is left out. In mine, the last four elements are [8, 4, 6, 6] and in the "correct" solution the last four are [4, 6, 6, 1] so clearly the two are just offset by this one extra element in mine, BUT the "correct" solution includes other 8s, so clearly the "correct" solution considers 8 to be one of the n minimum elements... I don't understand why the "correct" solution throws this particular 8 out when others are let in...

  • Minoru-kun Avatar

    I added a Rust translation, please take a look!

  • vizeit Avatar

    @FArekkusu, The description says there are 15 tests with array of size 300,000. Are there more tests than that? I ran tests on my machine and it finishes in 4.2 sec for that size but it is showing timeout error here.

  • krnets Avatar

    should be 5 kyu instead of 6 performance edition katas shoud be one or two kyu difference than original kata

  • docgunthrop Avatar

    I must've gotten lucky; I used my same solution from the non-performant version and passed in 11976 ms. How is the average performance of any given solution for this kata?

  • JohanWiltink Avatar

    ( JS )

    There is one example and fixed test that does not conform to the Numbers range specified for the Performance tests. Is this intentional?

  • Xavion Avatar

    This comment has been hidden.

  • Dragon-God Avatar

    This comment has been hidden.

  • lechevalier Avatar

    This kata was not as interesting as it seems. Micro-optimization is vastly a waste of time and enforcing it on purpose should be avoid.

    At the moment, Python solutions are nearly limited to the same bytecode - solving this kata sums up to get the right serie of instructions or to resign. Moreover, many sorting-like solutions and even linear solutions are rejected due to the very specific test suite.

    I can't say I have learned something from this kata so I can't speak longer, but I was quite disconcerted by such a kata...

  • Blind4Basics Avatar

    This comment has been hidden.

  • FArekkusu Avatar

    UPD: Somebody approved it with the same rank as non-performant version.

    Insane >_>

  • Unnamed Avatar

    Your solution is O(len(arr) * log(len(arr))) in the worst case, so what exactly are the requirements?