I have used the following logic(in java) but the solution gives a runtime error.
long a=new long[n+1];
I have given conditions to ensure nothing goes out of bounds. When I ran my programme in my IDE with a large input for n it gave a heap space error. How can I solve this?