• + 4 comments

    I wonder can it break the stack with sufficient linked-list length?

    • + 0 comments

      It can and will

    • + 0 comments

      Yeah. Recursive solutions generally don't work well when n is very big because of the demands on the stack. Classic example is computing the Fibonacci numbers. Compare the recurisve solution against the iterative one.

    • + 0 comments

      Yes, I agree and this can be an important consideration for large data sets or relatively large data sets on platforms with restricted stack sizes. If Hackerrank doesn't already, I think they could include variations on problems like this that enforce iterative solutions.

    • + 0 comments

      This immediately came to mind for me. It might look really nice, and really neat, but you would never do this in reality. You run the risk of overflowing the stack.