I was solving <a href="https://www.hackerearth.com/code-monk-dynamic-programming/algorithm/samu-and-shopping/description/">this</a> question on dp and I use Java as my preferred language for programming.↵
↵
But, I got a stack overflow error when I submitted the solution in Java, while the same code when converted into C++, ran perfectly fine.↵
↵
Here is the Java submission : <a href="https://www.hackerearth.com/submission/key/541c2507727643e38091bd6d40fda06b/">link</a><br />↵
and here is the C++ submission : <a href="https://www.hackerearth.com/submission/key/2ad686aaeeee49f8bdc7939e8dee9140/">link</a><br />↵
But, I got a stack overflow error when I submitted the solution, while the same code when converted into C++, ran perfectly fine.↵
So, I searched on the internet and found out that Java's stack space is very less. :/ <br />↵
So, is there any way I could solve this question recursively in Java? I don't want to switch to C++ as I am very comfortable with Java and really like to code in it.↵
↵
Java users, do you always implement an iterative version of an algorithm which could be solved recursively?
↵
But, I got a stack overflow error when I submitted the solution in Java, while the same code when converted into C++, ran perfectly fine.↵
↵
Here is the Java submission : <a href="https://www.hackerearth.com/submission/key/541c2507727643e38091bd6d40fda06b/">link</a><br />↵
and here is the C++ submission : <a href="https://www.hackerearth.com/submission/key/2ad686aaeeee49f8bdc7939e8dee9140/">link</a><br />↵
So, I searched on the internet and found out that Java's stack space is very less. :/ <br />↵
So, is there any way I could solve this question recursively in Java? I don't want to switch to C++ as I am very comfortable with Java and really like to code in it.↵
↵
Java users, do you always implement an iterative version of an algorithm which could be solved recursively?