If I've written a function with a void return type and want to memoize it, how should I implement it?
void rec(int i, int flag, int sum, int& maxi, int n, vector<int>& arr, int count) {
if (i == n) {
if (count <= 4) {
maxi = max(maxi, sum);
}
return;
}
if (flag) {
rec(i + 1, 0, sum - arr[i], maxi, n, arr, count + 1);
rec(i + 1, 1, sum, maxi, n, arr, count);
} else {
rec(i + 1, 1, sum + arr[i], maxi, n, arr, count + 1);
rec(i + 1, 0, sum, maxi, n, arr, count);
}
}
How can I memoize this code?