Not sure what all being said above, but cant it be done in just a simple way like
I accept, one gets good set of logics from a good and sound education, but i have to say that in field programing a lot of time experience helps to get simple and straight forward solution for your requirements. Optimization can follow on.
Are the requirements for problem 2 intended to rule out any form of recursion?
No.
Not sure what all being said above, but cant it be done in just a simple way like
I accept, one gets good set of logics from a good and sound education, but i have to say that in field programing a lot of time experience helps to get simple and straight forward solution for your requirements. Optimization can follow on.
This solution is correct, but only works up to i ~= 30,000 because of stack depth limits.