Alternative of arrays, Array takes more memory, not able to submit

Though out my code i used lot’s of arrays and loop. the output of program is correct but would not able to submit. The codechef compiler it showing runtime error "too much memory has used ".
Is there any alternative of array that may take less memory and work same as array.
My second question is, Which type of primitive data type i take for 10^18 integer value.

1 Like

It depends on what you want to do. In Java, you can look at the collections framework, wich is part of the JDK (ArrayList, LinkedList, HashSet, etc.).

The primitive data type you’re looking for is “long” (in Java). I think it is “long long” in C++.

1 Like

I’m afraid that there is nothing more memory efficient than array, so if you have memory problems with arrays, you will have bigger problems with collections…


Still, it depends of how and why you use it. Sometimes collections are much more convenient than arrays (ie. if you don’t know the size of your data in advance, you don’t want to allocate a really big array “just in case” :wink: ).

For first :
I think you should consider rechecking your algorithms, maybe that question could be solved without taking that much memory…!!

For your second answer :

long long int in C++/c
long in java