How to accumulate an array of size 10^9

hello @zabhishek

dont use array instead use map to memoise the result.
like this->