Alternate way of storing data of array size 10^9

My program is giving runtime error when i exceed my array size beyond 10^7 , can anyone help me to solve this issue :slight_smile:

Then you should find another algorithm for the problem. You may consider the following things:

  1. The array of size 10^9 takes 100 times more memory than 10^7 size array. Considering it an int array, this array alone will take memory of around 3800MB. Most problems do not allow this amount of memory.

  2. Even if you’re able to declare an array of such great size, You won’t be able to apply a linear time algorithm in many of the problems as it will probably exceed the time limit.

  3. To get a hint of the approach, you can look at other solutions’ memory and execution time.

  4. If the required array in the problem requires such an array, but it would be sparsely filled, then you may consider hashing.


If it is a contest problem, remove the solution link as soon as possible!

As for the approach, you’ll find much smarter solutions, once the contest ends. (:

1 Like

Declare array as global i.e. before int main().

Got ur idea i ll try finding some other approach :slight_smile:

In your situation, point number 3 will surely help you out

1 Like

i think you are trying to solve EGRKAKE…you can do it with very simple trick…now recognize that TRICK by your self

1 Like

okk @ xariniov9

i found others are also doing the same mistake and got 25 points but in next 4 minutes they got 100 points , how can they do this :stuck_out_tongue:

Got it complexity will be O(1)