Ad
  • Default User Avatar

    You need to give n sequential numbers the sum of which will equal to the cube of the given number. For example if n =4, you will have to find 4 odd numbers the sum of which will equal to 4^3. If n=6 you have to find 6 odd numbers the sum of which will equal to 6^3. Also, you have to follow the mathematical formula according to which a1, a2=a1+2, a3 = a2 +2 etc. Hope this helps

  • Default User Avatar

    Thank you very much,that was very helpful.Im beginner and i wouldnt consider this approach.

  • Custom User Avatar

    Your solution is too slow, especially for more difficult/larger inputs. The computational complexity of some problems grows rapidly with input size and sometimes trivial, naïve solutions pass for small inputs, but are not sufficiently performant for more challenging scenarios. You probably need to think of a better approach: some optimizations might help, but also might not. In the latter case, you probably need to think of a better algorithm.

    Tl;dr, you need a faster code. Most passed solutions can solve this kata within 1000ms.

    Troubleshooting Your Solution

    (Hint: try to look for pattern instead of brute-forcing)

  • Default User Avatar

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

  • Custom User Avatar
  • Custom User Avatar
    • Description should be language-agnostic

    • Probably better to use KaTeX for the mathematical part of the code

  • Custom User Avatar

    Thanks for the nice kata!

  • Custom User Avatar
  • Default User Avatar

    I still do not understand:
    [1, 3, 5, 7, 9, 11, 13, 15], N = 4

    • sequential - True
    • odd - True
    • equal to cube N - True

    findSummands(3) = [7,9,11] // because 7 + 9 + 11 = 27, the cube of 3. Note that there are only n = 3 elements in the array.

    added:
    I think I understand now! Thank you!

  • Custom User Avatar

    It is in the description, you need to take a closer look (Admittedly, it's easy to overlook that single character n).

    The description states:

    ... your task is to find n consecutive odd numbers whose sum is exactly the cube of n

    findSummands(3) = [7,9,11] // because 7 + 9 + 11 = 27, the cube of 3. Note that there are only n = 3 elements in the array.

    ... return an array of n consecutive odd numbers

  • Default User Avatar

    Misleading description! (python lang)
    From the description: "you need to find consecutive, odd numbers whose sum is equal to the cube of a given number."

    Using the example N = 4, as a result, all tests pass, except for the length test:

    • iterate from the beginning: sum([1, 3, 5, 7, 9, 11, 13, 15]) == 4 ** 3 Incorrect length for n = 4: 8 should equal 4
    • iterate from the end: sum([31, 33]) == 4 ** 3 Incorrect length for n = 4: 2 should equal 4

    There is still 1 option left for N = 4: [13, 15, 17, 19]. Judging by the tests, this is exactly what is needed, how should I guess about it?

  • Default User Avatar

    Looks good. Thanks!

  • Custom User Avatar
  • Custom User Avatar

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

  • Custom User Avatar

    Should be fixed, could you please verify.

  • Loading more items...