Ad
  • Custom User Avatar

    In Python, there exist ways to increase the recursion limit... ;)

  • Default User Avatar

    It's up to you to write code that stays within the limits of the language you choose.
    Some languages eliminate the current call frame when you do tail recursion (no further actions after the call returns), making it a jump to the top just like a loop. You can do this yourself in other languages as well through trampolining. Sometimes you can also write it so that you get log(n) call depth and log2(1000000) is about 20 so plenty of room if you do that. Probably not worth it though, easier to use a loop. A tail recursive function directly translates to a loop (set the new state then jump to the top)

  • Default User Avatar

    Hi there,

    I wrote the function recursively, and it passed all the tests apart from 1. This is the error the feedback gave:

    RecursionError: maximum recursion depth exceeded in comparison

    Is recursion in general discouraged if we are using large inputs? Would a for cycle be a better alternative in this case?