Ad
  • Custom User Avatar

    OK, recursion is bad for this.
    I solved it in iteration methos.

  • Custom User Avatar

    Exactly.
    Too slow in JS and I cannot see a better way for this other than recursion.
    When I try (-50) I don't even see the process ends.

  • Custom User Avatar

    How would one begin doing this without using recursion?

  • Default User Avatar

    The test cases in the javascript translation can be above 1000 so recursion is to slow.

  • Custom User Avatar

    The "Submission timed out" is a Codewars internal thingy (check the GitHub wiki on more information about that). However, a simple recursive will fail, since each non-terminating call will run the function twice, resulting in an exponential runtime (O(2^n)). Just draw the callgraph on a piece of paper and you will notice that it get's quite big for small values like 5.

  • Default User Avatar

    What language are you using?