I’m using this statement
//some code
int a[][]=new int[5000000][5000000];
//some code
and running it with command
java -mx512m Test
It is giving OutOFMemoryError: Java Heap space indicating the line number of the mentioned statement in the stacktrace
How do i solve this problem
Edit:
I’m trying to solve a practice problem on codechef
I think the data structure you are looking for is a sparse matrix. Store your elements along with their coordinates in a map data structure (eg.
Map<Integer,Map<Integer,Integer>>for a 2d sparse array) and just assume anything not in the map is zero.