Is it a good practice to store the results of various test cases in a array then giving the output so that the output becomes fast…
The constraints being less which ensure that the results could be stored in a array
for eg
storing all the prime numbers in a array and then outputting the required number of prime numbers between 2 numbers
There are two possible angles from which one can answer this:
a) Can I store results on an array, as in, pre-compute values so subsequent calculations are performed faster?
OR
b) Can I store all output on an array and print entire array afterwards?
Answer to both questions is yes you can
However, for question a) you must be aware that sometimes the source code size limit might not allow you to store huge arrays directly “hard coded” in your code.
If that’s the case, than possibly using pre-processing might not be the way to go