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.).
http://docs.oracle.com/javase/6/docs/technotes/guides/collections/index.html

The primitive data type you’re looking for is “long” (in Java). I think it is “long long” in C++.
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

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…

3 Likes

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

For your second answer :

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

2 Likes

True.
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: ).