Some peple talk about memoization but what data to memoize?
I only use pure array with numbers inside. So the next group is just arr[index+1], memoization can't beat that.
And a arr[index] gives also the exact number of money earned. Again, memoization can't be useful because there is no compute task.
Maybe to look for a certain pattern can match in certain cases. Is it the way to go ?
Update : detect a cycle and memoize it is the way to go . But don't forget to remove all printErr unless the large data set doesn't pass