6 kyu

Length of missing array

2,170 of 16,922user5036852
Description
Loading description...
Arrays
Algorithms
  • Please sign in or sign up to leave a comment.
  • tchaflich Avatar

    Considering just how many people missed part of the description, I suggest adding a fixed test case to the sample to account for it. That would likely reduce the amount of comments complaining about random tests being "bugged".

  • DOEHOONLEE Avatar

    Honestly, a fun kata, but.. a kata should be made so that we guess the solution, not the description. I spent more time guessing the description than I spent for coming up with a solution. The details/description should be re-written.

  • danik00111 Avatar

    omg the edge cases almost made me give up :sob::pray:

  • binarybynature Avatar

    (PHP) My solution passes the test. But when i click submit it fails the same basic test. How is that possible?

  • SS-Stefanov1 Avatar

    Wrong for [[2, 4], [], [4, 2, 0], [3, 4, 2, 3]]: expected 1 to equal +0

    0,2,3,4 should return 0 instead of 1 ? wtf..

  • dvsherbakov Avatar

    the task is good, but the task is described in an asshole, and the tests do not show what the problem is

  • Tigvzxx Avatar

    This comment has been hidden.

  • KayleighWasTaken Avatar

    Python random tests are broken:

    array_of_arrays = [[85, 50], [8, 19, 38, 15, 90], [], [87, 95, 55, 29], [4, 52, 54, 99, 85, 18], [26, 91, 1, 99, 9, 29, 36], [50]]
    3 should equal 0
    

    Present lengths are [0, 1, 2, 4, 5, 6], so answer should be 3, but it is expecting 0.

  • saudiGuy Avatar

    python new test framework is required. updated in this fork

  • saudiGuy Avatar

    This comment has been hidden.

  • ejini战神 Avatar

    Actual and expected are flipped in PHP

  • pibelanzallamas Avatar

    hello! i don't understand what Should pass edge cases means cheers!

  • Koley Avatar

    This comment has been hidden.

  • Lehinas Avatar

    how to solve this problem: TypeError: Cannot read properties of null (reading 'length'). when function called without argument we get this error(as i know), so how i can solve it for test...?

  • AlexDRichards Avatar

    The way the tests are written for this kata make it hard to debug.

  • Igor Dadonov Avatar

    For those who have 'length of null' error - one of the test cases includes null value instead of subarray. For better understanding:

    [[1], [2, 4], [5, 6, 7], null, [6, 7, 8, 9]].

    I've been suffering with this problem for an hour or so,this specific test in this kata just suck!

  • ejini战神 Avatar

    Function name in Ruby should be snake_case

  • marjan Avatar

    How do you know what is the size of original array?

  • davidnduffy Avatar

    This comment has been hidden.

  • mitstack Avatar

    I am not going crazy but my array is empty and I am getting the error that TypeError: Cannot read property 'length' of null at getLengthOfMissingArray (test.js:4:9

    my code is : [].length == 0 return 0

    but instead I am getting the error.

  • rsschool_f78947060131757d Avatar

    main test passes without errors.

    send attemp : value passed - always different 28 or 32 or 36

    Time: 835ms Passed: 33Failed: 10 Errors: 1Exit Code: 10

    TypeError: Cannot read property 'length' of null at getLengthOfMissingArray (test.js:4:9) at Context. (test.js:38:24) at processImmediate (internal/timers.js:464:21)

    what could be the reason for the test or my code ?
    
  • E-Codes Avatar

    Test cases are poorly written.

  • LS2008 Avatar

    Nice kata, but I accidentally pressed skip and didn't get the point, damn...^^

  • mo.mo. Avatar

    It's like an issue in JS ReferenceError: Test is not defined

  • soyoonmoon Avatar

    This comment has been hidden.

  • AliLtRP Avatar

    you should mention one of the testcases have null array !!!

  • Pursea Avatar

    Using javascript - Really enjoyed this kata, but it is almost as if the test suite isn't running the code properly. I used the failing random and basic test as a test in VSCode and my solution returned the correct answer. Only seems to concern the [] returns 0 criteria. The CW test suite says the ouput was 4 but VScode test suite says the output is 0... Is it just me?

  • Emanuel 1988 Avatar

    In the Java version the random test is buged. I get the following message: "Wrong for [[1, 1], [3, 3, 4, 0], [4], []] expected:<0> but was:<3>" It always expects length 0.

  • DurusbekSadykov Avatar

    This comment has been hidden.

  • kennyliveforever Avatar

    I have passed basic test, but then I had attempted a solution, I rescieved an error:

    TypeError: arrayOfArrays is not iterable at getLengthOfMissingArray (test.js:11:23) at Context. (test.js:52:23)

    All other test passed.

    Maybe someone knows how solve that problem?

  • laurelis24 Avatar

    [[3, 1, 1], [2, 1, 2, 2], [2, 3], [2, 4, 1, 3, 4], [4, 1, 2, 3, 3, 3], [3, 0, 1, 3, 0, 4, 0], [4, 2, 2, 4, 2, 0, 4, 2, 0], [4, 2, 4, 4, 0, 2, 0, 4], [2, 4, 3, 3, 2, 0, 1, 0, 2, 0, 4]]: expected 1 to equal 10 It misses array length of 1. Why it asks me for 10?? Edit: I understand now that i need to find which length misses between the given lengths...

  • user1430804 Avatar

    second solution is best practice in my opinion.

  • farhanaditya Avatar

    JS: Why if there's an empty array, the function should return 0? They're valid arrays and they have lengths

  • dummyaccount Avatar

    This comment has been hidden.

  • ejini战神 Avatar

    Typescript 3.3 or above should be enabled

  • sorinchihaia Avatar

    This Kata is not working properly, event if my tests are passing more then 3,4 attempts there is not button to submit my solution. Please investigate. I'm getting this for some reasons even if the tests are passing. Traceback (most recent call last): File "tests.py", line 55, in test.assert_equals(get_length_of_missing_array(test_case), reference(test_case)) File "/workspace/default/solution.py", line 2, in get_length_of_missing_array array_of_arrays.sort(key=len) TypeError: object of type 'NoneType' has no len()

    I'm using this solution: def get_length_of_missing_array(array_of_arrays): array_of_arrays.sort(key=len) counter = None print(array_of_arrays) for x in range(len(array_of_arrays)): if len(array_of_arrays[x]) == 0 or len(array_of_arrays) == 0: return 0 if counter != None and counter + 2 == len(array_of_arrays[x]): return len(array_of_arrays[x]) - 1 counter = len(array_of_arrays[x]) return 0

  • sorinchihaia Avatar

    Even if my tests are passing I'm not able to send the solution and the only option is to attempt more than 1 time. Anyone can help me with this?

  • EsenDzhumaev Avatar

    This comment has been hidden.

  • vvedenskiy Avatar

    I would not say that the kata is bad, but it annoys me personally that in one kata you need to solve two unrelated problems: the kata itself and a large number of validations. I would split these tasks into two independent kata.

  • qila_manta Avatar

    why in my PlayCode sandbox everything works fine with the same code but there it cant pass through tests....

  • willfowls Avatar

    test cases are super annoying. it is much easier to work with when you can see the return values on a one by one test basis.

  • No Name Mystery Avatar

    This comment has been hidden.

  • scrinpwnz Avatar

    This comment has been hidden.

  • 3lide Avatar

    This comment has been hidden.

  • AnotherStupidDev Avatar

    You have to mention, what one of your testcases is simple (null). Not an array with null, not an empty array, nothing. Took me 30 minutes to realize, what was wrong.

  • red_mould Avatar

    I agree with the comment of kfh132003. Need to add in "visible" tests an array of arrays like [[1, 2, 3, 4], [1, 2, 3], [1, 2, 3, 4, 5, 6]] --> 5 because in random test cases such arrays are found. P.S. Kata -> good =)

  • manianis Avatar

    There is no need to sort the array in order to find the length of the missing one.

  • caiblack Avatar

    I think that the value used in the assertEquals in the "Attempt" tests set IS incorrect for some test.

    [[40,50,27,7,29,50],[16,10,43,15,27,13,47,46,23],[18],[19,45,4,10,8,10,35,37],[43,48,27],[40,42,29,12],[7,22,28,0,11,0,14],[30,8,31,33,36,38,13,2,12,22],[],[45,1,43,2,25]]

    The assertion for this array of arrays is expecting 1 as the result, but the array size that's missing is 2.

    I added that same array with the expected '1' to the sample tests. It fails. When I change the expected size to 2, it passes.

    My code outputs the size of the passed sub-array sizes. Here are my test cases, and the code output:

    class MyTestCases extends TestCase { public function testBasicTests() { $this->assertSame(getLengthOfMissingArray([ [ 1, 2 ], [ 4, 5, 1, 1 ], [ 1 ], [ 5, 6, 7, 8, 9 ]] ), 3); $this->assertSame(getLengthOfMissingArray([ [ 5, 2, 9 ], [ 4, 5, 1, 1 ], [ 1 ], [ 5, 6, 7, 8, 9 ]] ), 2); $this->assertSame(getLengthOfMissingArray([ [ null ], [ null, null, null ] ] ), 2); $this->assertSame(getLengthOfMissingArray([ [ 'a', 'a', 'a' ], [ 'a', 'a' ], [ 'a', 'a', 'a', 'a' ], [ 'a' ], [ 'a', 'a', 'a', 'a', 'a', 'a' ]] ), 5); $this->assertSame(getLengthOfMissingArray([ ]), 0); $this->assertSame(getLengthOfMissingArray([[40,50,27,7,29,50],[16,10,43,15,27,13,47,46,23],[18],[19,45,4,10,8,10,35,37],[43,48,27],[40,42,29,12],[7,22,28,0,11,0,14],[30,8,31,33,36,38,13,2,12,22],[],[45,1,43,2,25]]), 2); } }


    MyTestCases testBasicTests -------- Log ---- sizes: 1,2,4,5 Missing: 3 sizes: 1,3,4,5 Missing: 2 sizes: 1,3 Missing: 2 sizes: 1,2,3,4,6 Missing: 5 sizes: 0,1,3,4,5,6,7,8,9,10 Missing: 2


    I cannot pass this kata until the source data is correct.

  • richard.gaugler Avatar

    I'm getting the Error Code 139 and I don't even know what this means.
    This doesn't only concern this Kata, I've had this issue on many Katas and I don't know where this error comes from.
    However the tests look tricky, and as far as I'm concerned my code should work

  • kgeebro Avatar

    I really have no clue but I get the results below. I thought if you get all the assertions it's a full pass if someone could explain I would love it. I'm defintely trying to learn.

    KataTests Basic Tests (6 of 6 Assertions) Random Tests (40 of 40 Assertions)

    Test Passed: Value == 0 (<---Obviously just one of the passed tests but right below it is the error) TypeError: Cannot read property 'length' of null at getLengthOfMissingArray at /home/codewarrior/index.js:45:23 at begin at it at /home/codewarrior/index.js:34:3 at /runner/frameworks/javascript/cw-2.js:152:11 at Promise._execute at Promise._resolveFromExecutor at new Promise at describe at /home/codewarrior/index.js:33:5 at /home/codewarrior/index.js:81:5 at Object.handleError

  • kgeebro Avatar

    This comment has been hidden.

  • 5meh Avatar

    This comment has been hidden.

  • abelgoodwin1988 Avatar

    Hey, the basic test for the empty array of arrays is returning some kinda of javascript error within the codewars js engine. I tested on a couple different versions of JS locally and got no issues. This Kata is currently unpassable with this issue.

  • mungiu Avatar

    In JAVA:

    Basic test passing. Then I click ATEMPT, Random test is passing but Basic Test is not passing. For the same code... ???

    Please help vote up this comment and resolve this issue.

  • rababa Avatar

    This comment has been hidden.

  • storycoding Avatar

    Could you entertain me with an explanation as to why there is no description of the assertions?

    While the rules of the problem are valid, the test cases are extremely unclear.

  • Powakedown Avatar

    I got error message even the test is passed. I delete all the code, just kept the return 0 if array.empty? and i got error below the right return.

    Test Passed: Value == 0 # main.rb:5:in getLengthOfMissingArray' main.rb:21:in block (2 levels) in ' /runner/frameworks/ruby/cw-2.rb:180:in wrap_error' /runner/frameworks/ruby/cw-2.rb:72:in it' /runner/frameworks/ruby/cw-2.rb:206:in it' main.rb:10:in block in ' /runner/frameworks/ruby/cw-2.rb:55:in block in describe' /runner/frameworks/ruby/cw-2.rb:46:in measure' /runner/frameworks/ruby/cw-2.rb:51:in describe' /runner/frameworks/ruby/cw-2.rb:202:in describe' main.rb:9:in ` '

  • Sandro Avatar

    This comment has been hidden.

  • kingchunlam Avatar

    This comment has been hidden.

  • Sir Bengtsson Avatar

    What`s wrong?

    BasicTests Runtime Error Occurred java.lang.NullPointerException

  • Farouq Avatar

    This comment has been hidden.

  • oahnus Avatar

    when I use Arrays.stream(arrayOfArrays), I got

    /home/codewarrior/src/main/java/Kata.java:9: error: cannot find symbol
        Arrays.stream(arrayOfArrays);
        ^
    symbol:   variable Arrays
    location: class Kata
    
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':compileJava'.
    > Compilation failed; see the compiler error output for details.
    
    *
    

    why?

  • canzoroglu Avatar

    I got "TypeError: Cannot read property 'length' of null at getLengthOfMissingArray...." error at basic test. Other than that, I've passed all tests. What may cause the problem? Also, I didn't understand "If the array of arrays is null/nil return 0" part of the instruction. Because in the sample test ([ [ null ], [ null, null, null ] ] returns 2 not 0. Could you give any example for null array of arrays?

  • nikitka320 Avatar

    This comment has been hidden.

  • ronsardji Avatar

    What about there is only one array, for example [[1,2,3]]? I'm confused.

  • ViktorMorgachev Avatar

    My code working is properly, but RandomTest not passed, i don't know why!!!!

  • tomophilia Avatar

    Hello, I am running into the same issue as fesenkod from a year ago and I'm also using Python:

    STDERR: Traceback: in in get_length_of_missing_array TypeError: object of type 'NoneType' has no len()

    I check (or I think I'm checking) for an empty array and for None. I pass all tests. I'm not sure what to do. Any help would be appreciated. Thanks

  • MylesWritesCode Avatar

    This comment has been hidden.

  • AMHD Avatar

    I have an error with the testing: "Wrong for [[1, 4, 0, 3, 2, 1, 1], [1, 0, 4, 2, 3, 2], [2, 4], [], [1, 4, 1], [0], [3, 4, 0, 4, 2]] expected:<0> but was:<4>" though the missing array length should be 4...

  • nian370 Avatar

    My program runs well on g++ but failed the sample test. Does anyone has the same problem?

  • Riael Avatar

    This comment has been hidden.

  • fenchu Avatar

    I get a random test failure: aka '22 should equal 7'

    very confusing error message

  • TinoC Avatar

    The test is bugged! I had to hack my solution to pass it! whenever the shortest array in list of arrays is 0, the test expects 0 to be returned, which is wrong

  • Mio0516 Avatar

    System.ArgumentNullException : Value cannot be null. Parameter name: source

    How can I solve it? I do not have a variable named Source. I'm not good at english, so I'm using Google to translate.

  • simondein Avatar

    This comment has been hidden.

  • kfh132003 Avatar

    I analyzed RandomTest and I think author should added extra case in simple (visibly) tests or in description of task: What smallest inner (not NULL) array can have size > 1.

    Example: [[1, 2, 3, 4], [1, 2, 3], [1, 2, 3, 4, 5, 6]] --> 5

  • kfh132003 Avatar

    Is there option to see input arrayOfArrays in RandomTest? It is only test that doesn't passes in my case. I know there is source code in "Show Kata Test Cases" but is there easier way?

  • CupiNhockPham Avatar

    Thank SteffenVogel_79 !

  • 50fat Avatar

    How do you declare separate functions on this? I'm using C++11 and sort function in the algorithm library. It requires a 3rd argument which must a function returning a bool.

  • mdsfwrz Avatar

    3 different correct solutions (including the most upvoted, copy and pasted), passed the basic tests but gave a "SIGSEGV" error when submitting. Seems to be a problem with the Kata implementation.

  • Kirmakoff Avatar

    This comment has been hidden.

  • biillts Avatar

    Finally past the kata, just heads up anyone who may need help, this Kata meants:

    1. any element is null
    2. any element is empty
    3. or the arrayofArrays is empty or null return 0

    otherwise according to author's explanation.

  • tataton Avatar

    Misleading instructions, in a couple of places:


    "You get an array of arrays."

    One of the test inputs is an empty array, [], another is the value null, and others are arrays that contain the value null in place of one or more arrays. This makes your very first statement incorrect; the first two of these specific examples are not arrays of arrays, and you could easily argue that the thirs example is not either. (Is a mixed array of arrays and numbers an "array of arrays"? I don't think so. Likewise, I do not think a mixed array of arrays and null values is an "array of arrays".) You could dramatically improve the instructions for this kata by modifying this first sentence: "The input to the function may be null, or may be an array. If the input is an array, it may be empty, or may contain null values and/or one or more arrays."


    "When an array in the array is null or empty, the method should return 0 too!"

    So "when an array...is null", the method should return 0.

    An array cannot be null. It can contain null (or even multiple nulls), but it cannot be null. I think many of the questions asked in this thread relate to this misleading clause. You could correct this by modifying the misleading clause:

    "When a component array in the array is empty, or when the component is the value null, the method should return 0 too!"

  • Mystical Avatar

    This comment has been hidden.

  • yuraavakyan Avatar

    Hi everyone.I have problem in BasicTests.It throws a NullRefference exception,although in visual studio 2015 all the cases of basic tests work properly.Is here abyone who solved that problem?Random tests pass ok.

  • demonation Avatar

    i am truly amazed at how many people are complaining of the same problem.... it's almost as if no one reads the descriptions :') :')

  • dashing Avatar

    This comment has been hidden.

  • wobocy Avatar

    For java the answer is wrong, the answer of the following question should be 2 not 0! Wrong for [[1, 0, 3], [1, 1, 1, 1, 4], [4], [3, 2, 0, 2], []] expected:<0> but was:<2>

  • rcwestlake Avatar

    I am getting a TypeError (cannont read length of null). I have tried commenting out various parts of my code and still can't track it down. All the tests pass, just can't get rid of the error. Based on the instructions, "when an array in the array is null or empty, the method should return 0 too!" The issue is that in the first batch of tests there is one like this:

    Test.assertEquals(getLengthOfMissingArray([ [ null ], [ null, null, null ] ] ), 2);

    which has null, and the answer is still '2'.

    Any suggestions?

  • DmytroIv Avatar

    This comment has been hidden.

  • 1c7 Avatar

    the random test got problem??

  • rreily1978 Avatar

    I struggled with this one in Javascript, but mostly because I forget to appreciate how much leeway one is given in JS regards type checking. I learnt to really appreciate what undefined, null and the quirks of empty arrays in this kata.

  • robinmattheussen Avatar

    I liked it somewhat, but the large amout of tedious pre-conditions you have to check is annoying. Also, you should probably state more clearly that the length of the arrays can start at something higher than 1, because all the examples and tests do.

  • kakoma Avatar

    The basic and random tests in the full suite for PHP might have an issue. The result's always something similar to this: testBasicTests ✘ Failed asserting that 0 is identical to 1. Completed in 0.23ms testRandoms ✘ Wrong for [[],[39],[37,50,15],[49,36,16,17,14],[16,46,12,22,42,16,28,18],[44,18,15,13],[3,31,19,22,41,39,0],[28,37]] Failed asserting that 0 is identical to 6.

    Running the code separately actually returns the correct value - 6 for the random case (and whatever other random value the assertion returns). There must be an issue with how the execution's being done

  • MatteoLucarelli Avatar

    The solution was a bit triky because the description is not accurate.

  • mertas Avatar

    This comment has been hidden.

  • mercyg22 Avatar

    This comment has been hidden.

  • peteredworthy Avatar

    For the random tests in Java it appears to have multiple missing array lengths. e.g. Wrong for [ [2, 2, 1, 3, 4, 1, 2, 1], [4, 3, 4, 3, 1, 0, 4], [2, 0, 1, 0, 0, 1], --missing 5 [0, 3, 1, 2] --missing 3 --missing 2 --missing 1 ] expected: 5 but was 1

    It is true that 5 is missing but so is 1,2 and 3. Is it expecting to receive the largest missing array?

  • danicat Avatar

    I'm having a problem with random tests in C++. The problem states that there will be always a missing array, but it generated a test with continuous length values:

    len = 3 2 8 4 len = 4 5 3 6 7 len = 5 5 0 6 5 4 len = 6 0 3 1 1 8 6 len = 7 9 3 6 1 9 3 5 len = 8 9 0 3 0 7 4 2 8

    The test case expects 0 as output.

  • aaron0828 Avatar

    This comment has been hidden.

  • Andrew-Wei Avatar

    This comment has been hidden.

  • drippel Avatar

    The tests for this Kata do not work.

  • Zantonius Avatar

    This comment has been hidden.

  • RaStall Avatar

    My problem is that on random test i get this error message: Wrong for [[], [4], [1, 4, 4, 3], [4, 0]] expected:<0> but was:<3> However You can easily see that expected number should be 3 as stated, not 0.

  • Yasmin  Avatar

    I saw some other people had this problem with different languages- I have it with JS. All tests pass (0 fail) but because of this error I can't submit. I'm not even using length to check the array, for example :

    arrayOfArrays = arrayOfArrays.sort(function(a,b){ if(a =="" || b==""){return 0;}

    The Error: TypeError: Cannot read property 'length' of null at getLengthOfMissingArray at begin

    Any ideas or Tips?

  • lalala_ Avatar

    This comment has been hidden.

  • Dentzil Avatar

    C++-Translation kumited!

    Please check it and approve! Thanks. ;)

  • pyrosomida Avatar

    This comment has been hidden.

  • josy Avatar

    This comment has been hidden.

  • josy Avatar

    I ran the code in other platform and it was successed.But when I ran the code in this platform it passed too,it gave an error that length is not a function of null

  • candrabeqx Avatar
  • dinglemouse Avatar

    Nice Kata. Thanks!

  • san.reddevils Avatar

    I am facing issue. Got the result "You have passed all tests! :)" on BasicTests while i clicked RUN TESTS. But on SUBMIT i am getting an System.NullReferenceException on BasicTests while the Random Test got passed.

  • user5036852 Avatar

    Why are giving people bad to this kata? If you have/have had problems with the kata, then create an Question or an Issue. Bad voting means, you hated it! I DO NOT UNDERSTAND THOSE PEOPLE! Really!

    To create a kata, even an easier one, is always work and time intensive! So it is like a "F U" for the author, who spends time here for you and the community!!

  • fesenkod Avatar

    When I run random tests I got following error:

    Random Tests ✔ Test Passed ✔ Test Passed ✔ Test Passed ✘ 0 should equal []

    I cannot see where in the instructions written that we should return an empty list. So, it may be considered as issue.

    UPD: and when I run random tests several times I also often obtain such error: STDERR: Traceback: in in get_length_of_missing_array TypeError: object of type 'NoneType' has no len()

  • suic Avatar
  • HerrWert Avatar

    Hat Spaß gemacht! :-)

  • suic Avatar

    Hi, there's some issue with random tests. See the example below.

    Regards,

    suic

    E. g.:

    ✘    Wrong for [[4, 4, 4, 0, 2], [], [2], [0, 2, 4, 2], [3, 2, 3, 3, 0, 2], [1, 2, 4]]
      Expected: 0
      But was:  2
    

    But:

    sorted = [[], [2], [1, 2, 4], [0, 2, 4, 2], [4, 4, 4, 0, 2], [3, 2, 3, 3, 0, 2]]
    lengths = [0, 1, 3, 4, 5, 6]
    
    // ergo:
    
    result = 2