Perfectly running code giving run error


This code is running perfectly everywhere but gives run error on submission

@Garvit012,
n is too big to be made an array of. 1e9 * 4 Bytes =~ 3.5 GB.

then what should I do?

@Garvit012,
You should do it top down recursively, with map for memoization.