We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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.
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.
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.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Print in Reverse
You are viewing a single comment's thread. Return to all comments →
I wonder can it break the stack with sufficient linked-list length?
It can and will
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.
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.
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.