Ad
  • Custom User Avatar

    Clunky problem with elegant solution.

  • Custom User Avatar

    Yes, in general you should aim for time-complexity improvements (ie reduce the number of nested loops), rather than micro-optimisations

  • Custom User Avatar

    you need to implement a single-loop solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    There is a subarray which sums to 6, which is [4, -1, 2, 1]:

    [-2, 1, -3, 4, -1, 2, 1, -5, 4] 
                ^         ^
                +--sum=6--+
    
  • Custom User Avatar

    I'm having some trouble with the test. Shouldn't [-2, 1, -3, 4, -1, 2, 1, -5, 4] be equal to 1, and not 6?

  • Custom User Avatar

    Yes, the current test requirements allow naive solutions to pass, and this kata is tagged performance. If other languages also have tests that are too easy, they should be updated too.

  • Custom User Avatar

    okay, so I just now translated Edward's C code into Python, which beautifully passed the sample tests, but timed out on the fixed / random tests, so that would appear to be a good why that multiple languages should be adapted

    and gloriously, we have a piece of code to use as a litmus test (thank you OP) I'll get back to this tomorrow

  • Custom User Avatar

    but why? Edward does not have an answer to why, Bob has not stated why, so this issue is lacking that particular directive.

    I have not had a chance to look into why, so I still do not know why myself, but since I did the C translation seven years ago I will look in detail tomorrow if it has not yet been resolved.

    Meanwhile, it is not just C with low array lengths: C++, C#, and Java all have random test arrays averaging around 40 to 50 in length.

  • Custom User Avatar

    Yes, the tests need to be hardened in C. Other languages test arrays tens of thousands of elements long, but the arrays in C have a max length of 42 for some reason.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    I understand the logic behind the solution now(though I did not solve it on my own). It requires a level of abstraction I'm not used to yet. Rather than checking each Subarray, it can be done in a single iteration.

    Thank you.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    for some reason i didn't come to the obvious way of solving it and instead made a thrice-nested loop.

    nice one, though.

  • Custom User Avatar

    The reference solution returns true for 8821. It's your code which is returning false for it.

    Failed for input: 8821
    : expected false to equal true <- this was the expected one
    //           ^
    //    this is your answer   
    
  • Loading more items...