6 kyu

N smallest elements in original order

933 of 2,990GiacomoSorbi
Description
Loading description...
Arrays
Lists
Data Structures
Algorithms
  • Please sign in or sign up to leave a comment.
  • Damir_coder Avatar

    It's definitely a nice one. But not so difficul to solve.

  • Kees de Vreugd Avatar

    While trying to solve: "Wow, this is a lot harder than I thought" After solving, looking at the top-solution: "Oh, yeah, alright..."

  • JustAn0therDev Avatar

    Very nice kata! A bit more difficult than your average 6 kyu.

  • Iluxmas Avatar

    Nice one, a little bit harder than it seems at first sight!

  • NazikXY Avatar

    arr = [3, 3, -8, 7, 5, -1, 0, 0, 6, 6, -6, -8, -2, 3, 1, -8, -8, 7, 8, 7, 2, 2, 3, 10, -10, -1, 7, -9, -8, -1]
    n = 27
    It should work for random inputs too:
    [3, 3, -8, 7, 5, -1, 0, 0, 6, 6, -6, -8, -2, 3, 1, -8, -8, 7, 7, 2, 2, 3, -10, -1, 7, -9, -8]
    should equal:
    [3, 3, -8, 7, 5, -1, 0, 0, 6, 6, -6, -8, -2, 3, 1, -8, -8, 7, 7, 2, 2, 3, -10, -1, -9, -8, -1]

    So, the question is why the number 7 should not be included in the list of results at index -3(24), if 7 is among the 27 smallest elements of this array?
    I am not sure, but seems the test is broken or etc.

  • ndegz Avatar

    very nice kata!

  • raswonders Avatar

    I liked this kata, but sort algo on node.js turns stable only after node.js 11 which makes it bit of a headache if you don't know. Could this use node.js > 11?

  • lemar.jul Avatar

    This comment has been hidden.

  • saudiGuy Avatar

    python new test framework is required. updated in this fork

  • Beefy1 Avatar

    This is a lot harder than 6 kyu, hence should be higher than 6 kyu. But that's just my opinion.

  • markinsurance Avatar

    Testing for [-7, 9, -8, -2, 2, 2, -4, -2, 1, -4, 7, 0, -8, -3, 9, -1, 10, -2, 6, 10, -5, 10, 0, 4, -2, 10, -2, -4, -7, 2, 4, -5] and 11 Expected: equal to [ -7, -8, -2, -4, -4, -8, -3, -5, -4, -7, -5 ]

    Why is here on "expected" field I see "-7, -8, -2, -4, -4 ..."? If I'm not mistaken, the answer should be "-7, -8, -2, -4, -2, -4 ..." as on the top we see that in a consecutive number -2 going before the second -4

  • farhanaditya Avatar

    JS: Node v12 should be used along with its proper assertion tools (Mocha + Chai).

  • stellartux Avatar
  • RNOH Avatar

    very nice kata!

  • user9644768 Avatar

    Ruby 3.0 should be enabled.

  • akar-0 Avatar

    In Rust the function name in the initial code (n_smallest) differs from the one tests expect (first_n_smallest).

  • WestwardLand968 Avatar

    Typo: bas should be base (first paragraph of description).

  • Stas1976 Avatar

    Hello, when I run test on site I'm getting

      Testing for [0, -2, 1, -9, -5, 0, -4, -3, 3, -5, -4, 8, -9, -8, 6, 9, 3, 10] and 10
      It should work for random inputs too - Expected: '[0, -2, -9, -5, -4, -3, -5, -4, -9, -8]', instead got: '[-2, -9, -5, 0, -4, -3, -5, -4, -9, -8]'
    

    but when I run it on my text editor I'm always getting correct solution [0, -2, -9, -5, -4, -3, -5, -4, -9, -8] not this one [-2, -9, -5, 0, -4, -3, -5, -4, -9, -8]

  • IAmRobotic Avatar

    Python tests are broken when it starts applying random inputs. The feedback given is not useful. Nevertheless ran the random inputs on my own and got the right answers. Something is wrong with the test cases.

  • Rud1 Avatar

    Fun kata, trickier than first expected.

  • IGNATDROZDOV Avatar

    Random tests for Python are broken: Testing for [1, -8, 8, 1, 7, 6, 7, 2, 2, 2, -8, -3, -8, -2, -6, -5, -9, 2, -8, 4, 1, -8, -9, 3, -5, -4, -8, -6, -3, 9, -1, -4] and 4 It should work for random inputs too: [-8, -8, -8, -9] should equal [-8, -8, -9, -9]

  • Minoru-kun Avatar

    I've added a Rust translation, please take a look!

  • nomennescio Avatar

    C test code has compiler warnings.

  • Schulzkafer Avatar
    Testing for [0, 0, 8, -4, -1, 0, -4, -7] and 5
    It should work for random inputs too - Expected: '[0, -4, -1, -4, -7]', instead got: '[0, 0, -4, -1, 0]
    

    Why? Isn't the original order?

  • mjsspencer Avatar

    Took tries on 2 separate days and a lot of frustration but managed to do it and learned some new things in the process, great kata, thanks!

  • Kennymelons Avatar

    Jesus. I actually spent my entire free Friday on this.I need to rest. 10 / 10 kata.

  • dlcoe Avatar

    C# - errors currently show name of the data structure rather than content.

    Test Failed
    Expected is <System.Int32[3]>, actual is <System.Int32[2]>

  • KataSideKick Avatar

    C# Translation added.Please review and approve~

  • AzoticPie Avatar

    Made a solution that works well in vscode, i got all the tests right but when i run it in codewars i get exit code: 139 Can anyone help?

  • MatokUK Avatar

    Haskell random test

    Falsifiable (after 24 tests):

    expected: [-13,10,8,-20,-18,-10,-5,-8,-3,-21,-5]

    but got: [-13,10,10,8,-20,-18,-10,-5,-8,-3,-21]

    ([17,-13,10,10,17,8,-20,-18,14,13,17,-10,-5,19,-8,14,-3,-21,13,-5],11)

    I dont understand why in excected result is only one 10... I am missing somethig?

  • Chrille Avatar

    This comment has been hidden.

  • monadius Avatar

    NASM translation. Please review and approve.

  • kingcobra Avatar

    Have you considered making a "performance" version?

  • Unnamed Avatar

    in case of duplicates, just return them according to their first occurrence(s) (counted from the left, as usual).

    Then firstNSmallest([1,2,3,4,1],3) should return [1,1,2] because all 1s are equal and their first occurrence is the 1st 1?..

  • Daniel729 Avatar

    In the instructions you said firstNSmallest([5,4,3,2,1],3) === [1,2,3] but it's actually firstNSmallest([5,4,3,2,1],3) === [3,2,1]